I am sure you have all seen the sites that have urls that look similar to books.php?id=4353. A URL like this not very friendly to users or even search engines. No person is going to remember that book number. Along with this search engines do not always properly crawl this.
Wouldn’t books/harry-potter.html make both users and search engines happy?
You might ask how an HTML file parse PHP code in this example. Well it works by using a simple .htaccess Unix file in the appropriate folder. You only need a couple lines in this file to make it work. Below is some sample code for the basics.
RewriteEngine On
RewriteRule ^books/harry-potter.html$ books.php?id=4353
Now this is fairly simplistic as this only work if a user types in the exact harry potter url. We can also make this Rule work for multiple books and change the parameter in the PHP file using a regular expression.
RewriteRule ^books/([a-z-]+).html$ books.php?title=$1
In the above code we are saying anything that after /books/ and before .html take that combination of letters and redirect to books.php with those values assigned to the title. The OPTIONAL parentheses allow us to use what is in between like a variable. The first parentheses are represented by $1, the second $2, etc.
Twitter
Follow me on Twitter to keep up to date!
RSS Feed
Keep up with all of our updates by subscribing to our RSS feed!
FaceBook
Join our group on Facebook and become a fan of us!