You need to provide the right path, use /test.php
instead and define your RewriteBase
. You should also provide a redirect status, either R=301
or R=302
in your RewriteRule
flags.
How do I use the mod_rewrite RewriteRule with an "R" flag to rewrite the url to one on localhost?
-
01-06-2022 - |
Question
I'm getting started on learning to use mod_rewrite. Here's my test .htaccess file under xampp/htdocs:
RewriteEngine On
RewriteRule ^something/?$ test.php [R,NC,L]
The rewrite works without the R
flag, but when I add that in and access localhost/something, the url it redirects to is http://localhost/C:/xampp/htdocs/test.php
.
When I searched it, I read that R
should only be used for external redirects, and to confirm this, I replaced test.php
with http://google.com
and it worked.
Is there a reason I shouldn't be trying to do this? If not, then how do I make it rewrite to localhost/test.php
?
Solution
OTHER TIPS
I think your problem is that "localhost" refers to "this" computer, so if from your browser's perspective, it is your browser's computer - i.e. your desktop, not your webserver.
Try doing a rewrite to http://yourservername/path/test.php