Why is Apache's RewriteRule revealing local paths?

.htaccess, apache, mod-rewrite

Solution

For those who happen to arrive here from Google (like me), the short checklist:

Make sure you have `RewriteBase /` (or any other value - the statement is what is important)

If you use redirect (`[R]`, `[R=30x]`, etc) - make sure the new URI starts with a `/` and contains a path relative to your domain root

(If above didn't help yet) Restart Apache, clear your browser's cache (especially if you have used `[R=301]` at some point)

That's what saved my day, maybe it will save yours too.

Problem

I'm trying to use RewriteRules in `.htaccess` with relative paths, but Apache seems to want to output the physical path instead of the server path whenever I try to output a relative path. Absolute and server-root paths work fine. For example: ``` RewriteEngine On # this works fine, 127.0.0.1/ab redirects to 127.0.0.1/cd RewriteRule ^ab$ /cd [R] # this doesn't work... 127.0.0.1/wx redirects to 127.0.0.1/C:/path/to/files/yz RewriteRule ^wx$ yz [R] ``` Adding a "`RewriteBase /`" solves the problem, but it's tedious to add the path to every `.htaccess`, and it makes it harder to change the directory structure. Is there a reason RewriteBase defaults to the current physical path instead of the current URI path?

Original source