Forum Moderators: phranque
RewriteEngine on
RewriteRule ^.*hello.html$ [YOURDOMAIN.com...] [L]
Echo.php is simple document that says "Hey you rewrote the URL!".
If I try the following URL on my server:
[YOURDOMAIN.com...]
It works as expected. Now I want to try matching sub-directories in the incoming URL. I tried this:
RewriteEngine on
RewriteRule ^.*/test/hello.html$ [YOURDOMAIN.com...] [L]
It no longer matches. I get a 404 error instead. I tested the RewriteRule regular expression in Kodos, a regular expression tester, and it worked fine. But for some reason, it doesn't parse when I try it on my server. I've tried other variations, and as soon as a I try putting a forward slash in the test part of a RewriteRule, it no longer matches.
What am I doing wrong?
Thanks.
But the local URL-path seen by RewriteRule in an .htaccess context is always stripped of its leading slash, so your subdirectory rule will never work as expected -- The leading slash in your pattern will never be present in the local ULR-path derived from your request if the code is in .htaccess.
You should also escape any literal characters that will otherwise be treated as regular-expressions tokens, "." for example.
To rewrite a request for "http://www.example.com/test/hello.html", in .htaccess, try:
RewriteEngine on
RewriteRule ^test/hello\.html$ http://www.example.com/test/echo.php [L]