Write SEO friendly URL
Here in this post we will learn technique to write SEO friendly URL by hiding .php extension with url rewriting using .htaccess. Using this technique you will see item.html in the address bar of the browser but the actual file name remains item.php and you don’t need to rename the file extension.
Why we re-write URL?
Actaully when search engine crawl the dynamic url like item.php?id=12, it does not give much importance to that url as search engine sees “?” sign and treat it as a url which keeps on changing. So here we will convert the dynamic url like item.php?id=12 to search engine friendly url like item-12.html. we will rewrite the dynamic url in such a way that it will display as item-12.html in browser’s address bar.
Requirment for URL rewriting
For url re-writing, You will have to load mod_rewrite module in apache server. you can also check mod_rewrite module load using phpinfo() php function.
Examples of url rewriting for seo friendly URL
For rewriting the URL, you will have create a .htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.
- Options +FollowSymlinks
- RewriteEngine on
- RewriteRule ^(.*)\.htm$ $1.php [nc]
The above example will rewrite the item.php to item.html. when a URL like http://phpzag.com/item.htm is called in address bar it calls the file item.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.
- Options +FollowSymlinks
- RewriteEngine on
- RewriteRule ^item-([0-9]+)\.html$ products.php?id=$1
The above example will rewrite the item.php?id=15 to porduct-15.html. when the URL like http://phpzag.com/item-15.html is called in address bar the file item.php?id=5 will automatically.
Follow @phpzag

nice tutorials