Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
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/(.*)$$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

One way is to have a separate VirtualHost with its own access_log file - e.g. if your domain is, you set up a separate VirtualHost with the DNS name, 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

Your Answer


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.