Debugging Rewrites That Result in “Not Found” Errors
If your RewriteRule directives
keep resulting in 404 Not Found error
pages, add the PT (PassThrough) flag
to the RewriteRule line. Without this
flag, Apache won’t process a lot of other factors that might apply, such
as Alias settings.
You can verify that this is the cause of your problem by cranking
the mod_rewrite logging level up to
9 and seeing that the entries relating to the RewriteRule mention something about prefixes
with document_root:
RewriteLog logs/rewrite-log RewriteLogLevel 9 %tail logs/rewrite_logip-address- - [date] [reqid] (2) prefixed with document_root to /usr/local/apache/htdocs/robots.textip-address- - [date] [reqid] (1) go-ahead with /usr/local/apache/htdocs/robots.text [OK]
Tip
Don’t forget to turn off the RewriteLog directive, or possibly just turn down the logging level, after you’ve done your checking! Otherwise, your disk space may disappear like the snows of yesteryear.
Without the PT flag, mod_rewrite assumes that any rewriting it
does will be the last URL manipulation the server needs to do for the
request. Because mod_rewrite
directives are handled very early in request processing, this can mean
that Alias, ScriptAlias and other URL manipulations may
not get executed. Specifying the flag tells mod_rewrite to not short-circuit processing
but to let it continue as usual.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access