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!

link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

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.

link|improve this answer
Thanks! This is what I needed to know... – Ricky Morse Feb 17 at 16:46
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.