Please can anyone tell me THE SIMPLEST WAY to write search friendly urls in a very explantory way.. I will be very thankful
using modrewrite (by .htaccess) if you do some research on google you will find out it is not so bad as you think to get the solution!
Imagine you have a script that when passed a category, prints out a list of books. /get-books-by-category.php?categoryid=123 Now you want a search engine friendly url? First thing, in the script that prints out those urls, change the url to something like this: /category/horror/ Then create a .htaccess file on your server to mod-rewrite those urls like this: RewriteRule category/([A-Za-z0-9_-])+/$ /get-books-by-category.php?category=$1 [L,QSA] This will rewrite those urls from /category/horror/ to /get-books-by-category.php?category=horror In your get-books-by-category.php script, you grab the category name from the querystring, look it up in the database to get the category id, then continue as usual. SELECT CategoryId FROM Categories WHERE CategoryName = 'horror' Now this adds an additional query every page, so their are a couple solutions to this. First, cache the look ups, of the categoryname to categoryid, or actually put the category id in the url. Using a url like this: /category/5/horror/ you can put the id in the url, and not have to look it up. The mod rewrite then becomes: RewriteRule category/([0-9]+)/([A-Za-z0-9_-])+/$ /get-books-by-category.php?categoryid=$1&categoryname=$2 [L,QSA] This captures the id from the url and the name (optional), passing that id to the script.