0

How do I get Apache to log particular Redirects in a separate log file?

I have a web site which includes links to an external site. I have been asked to keep track of how often users use these links. I can change them all to point to a redirector on my site, and use Apache RedirectMatch to then direct them to the correct location, but it would be easier if I could have these particular redirects logged to a separate file.

Thanks!

Ricky Morse
  • 173
  • 1
  • 5

2 Answers2

1

Define separate log file used if there is environment variable:

#Set your own file path and log file format
CustomLog /var/log/apache/redirects.log common env=redirected

Set this variable near every redirect (RedirectMatch or mod_rewrite, etc.):

SetEnvIf Request_URI "^/site" redirected=1
RedirectMatch ^/site/(.*)$ http://target.example.com/$1

You can also use SetEnv or mod_rewrite to set environment variables.

kupson
  • 3,578
  • 20
  • 19
0

One way is to have a separate VirtualHost with its own access_log file - e.g. if your domain is www.example.com, you set up a separate VirtualHost with the DNS name redirect.example.com, and all your links to external sites go through that host, and are recorded in that host's separate log file.

meulop
  • 726
  • 5
  • 10