This should be simple but I cannot figure it out. I have this very simple mod_rewrite rule and it just doesn’t want to work. This is the entire contents of the .htaccess file.
RewriteEngine On
RewriteRule ^([A-Za-z0-9-_/\.]+)/?$ index.php?page=$1 [L]
If I call the URL domain.com/foo it should rewrite it to index.php?page=foo. But instead, it rewrites it to index.php?page=index.php. I have tried multiple URLs:
- index.php?page=foo
- index.php
- /foo
- /
In all cases, PHP acts as if ‘page’ is set to “index.php”. It isn’t a fault with index.php because I replaced the entire contents of index.php with a script that simple echoed the value of ‘page’ and it still comes out as index.php.
Really lost where I’m going wrong here, any help would be awesome!
Thanks
Adrian
Any reason you can’t use something simpler, such as:
If you’re trying to keep existing pages from being re-written, then the
!-fwill take care of that (if file does not existandif directory does not exist, thenre-write)