Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

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.

share|improve this answer
    
Thanks! This is what I needed to know... –  Ricky Morse Feb 17 '12 at 16:46
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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