Apache CustomLog to log full URL
Solution 1
Keep reading the LogFormat
documentation and you'll find:
%...{Foobar}i: The contents of Foobar: header line(s) in the request
sent to the server.
Which means you could include in your configuration:
%{Host}i
The %v
and %V
directives may also get you what you want.
%v will always be the value of ServerName
(the "canonical name" of your virtual host). %V
may be the value of ServerName
, or it may be the value of the HTTP Host
header, depending on whether or not you have UseCanonicalName
enabled in your configuration (and whether or not the client supplied a Host
header).
Solution 2
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{Host}i%U%q" combined
%{Host}i%U%q
gives full url.
Solution 3
'%v' is the ServerName might be what you want?
Solution 4
Add %v
to your log format.
Something like this:
LogFormat "%v - %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined-vhost
CustomLog /log/file/location combined-vhost
Related videos on Youtube
AbdelKh
Updated on September 18, 2022Comments
-
AbdelKh over 1 year
I'd like to add a
CustomLog
directive to my apache configuration to log the full URL requested (or at least the host portion of the URL). I have several domains being handled by the same instance of apache, and would like to be able to distinguish the domains in the logs (as now all I see is "GET /"). I see in the documentation on LogFormat it lists%U
to print the path portion of the URL, but I'm looking for the host. -
AbdelKh almost 13 yearsIt looks like
%v
always returns the same string in my situation: the ServerName value regardless of what domain appears in the URL. But%V
looks like it does the right thing. -
AbdelKh almost 13 yearsWill
%{Host}i
work even for HTTP/1.0?%V
looks right at first glance, thanks! -
user2751502 almost 13 yearsI believe that %{Host}i (or any %{...}i construct) will only produce a result if that header actually exists in the request. So for HTTP/1.0, I would not expect it to be useful.
-
AbdelKh almost 13 yearsOne more clarification: So
%V
will be identical to%{Host}i
ifUseCanonicalName
is disabled? -
user2751502 almost 13 yearsAccording to the documentation, "With UseCanonicalName off Apache will form self-referential URLs using the hostname and port supplied by the client if any are supplied (otherwise it will use the canonical name, as defined above)." So
%V
will useServerName
if there is noHost
header. -
Michal Ambroz about 4 yearsPity that the %{Host}i%U%q ( or %{Host}i%<U%<q ) gives the full URL after all rewrites and not the original request from user. bz.apache.org/bugzilla/show_bug.cgi?id=64117