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.

Thanks for reading my question.

I'm using Debian5 + apache2
In apache2.conf I have multiple VirtualHost sections.
I have a main domain www.mymain.com in a virtual host section and multiple other domains in another virtual host section.
This later has a redirect command as follows
redirect 301 / http://www.mymain.com

All redirects work fine.
I would like to log the original domain used but have tried every format string at http://httpd.apache.org/docs/2.3/mod/mod_log_config.html#formats to no avail.

I have used all the standard logs and my own custom (all in) log for both VirtualHost sections and the required data doesn't appear anywhere in any of the log files.

ie user clicks link to www.myotherdomain.com they are successfully 301 redirected by apache to www.mymain.com

i'd like to see
blah blah www.myotherdomain.com blah blah
in the log

any input appreciated.

TIPS for folks with similar issue.

Most browsers cache 301 redirects. A brute force solution is to test using a portable install of Firefox (for example). Do tests and then delete and reinstall the application. Or just copy a clone of the original install anytime you want to do a test.

beware using *.domain.tld in serveralias commands in apache2.conf

UseCanonicalName Off applies even if all your servernames are virtual

remember that a 301 redirect generates 2 entirely separate log entries because it's 2 entirely separate events ie

browser requests www.myolddomain.tld -> server A returns 301 "command"
and
browser requests www.newdomain.tld (as listed in 301 cache) -> server B returns result

in theory server B may have no knowledge that a 301 occurred at all

Of course if server A and B are the same it would be very useful to be able to add the info to server B's logs.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

It sounds like you want to use a CustomLog format (for the virtual host that sends the redirect) that includes %V, and to make sure that you've set UseCanonicalName Off.

Log format documentation is here.

share|improve this answer
    
Thanks nickgrim. You are correct. –  John McNamara Jun 3 '11 at 9:30
    
It was a mess to resolve as I had several root causes involved. %v instead of %V due to a dogey font. Browser caching 301 redirects messed with testing. I had no idea UseCanonicalName Off effected this (makes no sense to me) so i had ignored it till now, Apache not flushing logs to disk when i thought it had and accidentally including an *.domain.tld server alias command when it shouldn't have been. –  John McNamara Jun 3 '11 at 9:37

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.