I am working with a CMS that needs pretty urls.
I found this snippet of htaccess code that I thought would solve all my problems:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?route=$1
Then on index.php I put this:
echo $_GET['route'];
If I go to mywebsite.com/cars, I can see “cars”. Perfect. But if I go to mywebsite.com/cars/ford, I get a “page not found”. What am I doing wrong? I want everything after the first “/” to be stuck into the route variable so I can explode it and make magic.
This should work flawlessly:
You don’t have to pass the URL as a GET parameter to your script, because that would cause additional headaches about escaping special characters. You can easily access your URL via $_SERVER[‘REQUEST_URI’].