I was looking for a simple solution these days to implement nice urls. I searched and found lots of tutorials on this but none of them where simple enough for what I wanted to implement: the simplest nice URLs possible, so I started from scratch and with guide the official mod_rewrite reference and with lots of trial and error I came up with the following solution.
Prerequisites: access to the .htaccess file, mod_rewrite enabled and php supported on your server.
I put in .htaccess
Options +FollowSymlinks RewriteEngine on RewriteRule ^(.+)/(.+)/(.+) index.php?a=$1&b=$2&c=$3 [nc] #RewriteBase /test/nice_urls
the first 2 lines are standard. They tell apache to start the mod_rewrite engine. The next line tells the rewrite engine to pick up any request of 3 parametes that is seperated with 2 slashes (/) and send it to the index.php assigning variables a,b,c the appropriate parameters. Last line was needed when I was playing around on my local development environment with XAMPP but apparently was not needed on my server so I comment it out (# in front, makes line a comment) but left it there for anyone that is using XAMPP
I put the following in the index.php just to see what each variable is assigned
echo "a = ".$_REQUEST["a"]; echo "b = ".$_REQUEST["b"]; echo "c = ".$_REQUEST["c"];
you can play around with this if you want.
This solution is good for 3 parameters in the URL. If you put less the apache would think you made an error (you can probably adjust the htaccess to account for less parameters). If you try put to put more then 3 parameters in it the 3rd variable and 2nd get assigned the last and one before the last parameters and the 1st variable get assigned everything else (you can probably adjust the htaccess to account for that too, I am not a mod_rewrite guru). But I thought about a more flexible solution that could handle any number of parameters passed using more php code instead of htaccess rules
Options +FollowSymlinks RewriteEngine on RewriteRule ^([a-zA-Z0-9/?+]+)$ index.php?a=$1 [nc] #RewriteBase /test/nice_urls2
this time I assign everything in the url to the one and only variable "a" and inside the php file I exploded the variable to get all the parts.
the index.php contains
echo "a = ".$_REQUEST["a"].; $params = explode("/",$_REQUEST["a"]); echo "Your gave ". count($params). " parameters"; print_r($params);
again you can play around with this if you want. Try putting as many parameters as you want and see what happens.