I\'m trying to use RewriteRules in .htaccess
with relative paths, but Apache seems to want to output the physical path instead of the s
Try this and tell me the result:
# this doesn't work... 127.0.0.1/wx redirects to 127.0.0.1/C:/path/to/files/yz
RewriteRule ^wx$ /yz [R]
put / before yz.
It's because of the [R] which means the server will redirect to the new path (so the user's browser will issue a new request with the newly sent uri) instead of translating internally the URI to a local path.
In your first RewriteRule, there is an slash in the new path, thus the server doesn't try to translate it to the local path, but in the second rule, there is no slash, this is why it redirects to a complete local path. This explains too why it works with the RewriteBase set.
Either remove the [R] (you can replace it by a [L] in your case, this avoids the server trying to match other rules once it found a matching one), or add a slash before "yz" in your second RewriteRule.
I'd suggest to simply replace the [R] with a [L]: this way, the user won't see the rewritten path, which is generally what RewriteRules intend to do (mainly for SEO purposes), unless you specifically want to redirect your users to a new URL.
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.