Forum Moderators: phranque

Message Too Old, No Replies

How to separate 301s in reporting?

         

anters

8:01 pm on Nov 12, 2019 (gmt 0)

5+ Year Member



Is there an easy way to create a separate log file for only the 301 redirects? The log file is massive and takes real computing effort to extract 301 redirects. Want to have a stand alone 301 log file that isn't overloaded with other data.

phranque

9:03 pm on Nov 12, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Use grep to filter out the 301 records. It is typically a very efficient tool.

lucy24

10:05 pm on Nov 12, 2019 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is it your own server?

:: detour to check Apache docs as I've got a nasty suspicion logging has to be defined before the response has been issued ::

Hm. There may be a loophole. You’re allowed to define logs based on an environmental variable, and environmental variables can be set in mod_rewrite, so if you add a flag to any RewriteRule that issues a redirect, it might work. See horse’s mouth [httpd.apache.org] for a little more about the [E] flag. You'd have to remember to add the flag to each separate rule (but you could, for example, omit it in your canonicalization redirect if you're not interested in tracking those separately).

So it would be something like
RewriteRule blahblah [R=301,E=otherlog,L]
in the area that issues the redirects, combined with
CustomLog "logs/redirects.log" common env=otherlog
CustomLog "logs/others.log" common env=!otherlog
in the overall config file.

Apache docs also helpfully point out that if you've got a bunch of VirtualHosts, you can say “GlobalLog” instead of “CustomLog” and the directive will apply to everything on the server.

Disclaimer: I have not personally tried this, as it requires access to a server config file.