Quick Search

url rewriting for seo friendly URL, Convert .php to .html

July 26th, 2010 by admin
Leave a reply »

 

For rewriting the URL, you should 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 following example will rewrite the test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.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$ item.php?id=$1



The following example will rewrite the item.php?id=5 to item-5.html i.e when a URL like http://localhost/product-5.html calls item.php?id=5 automatically.

Posted in PHP Development

You can follow any responses to this entry through the RSS 2.0 Feed. You can leave a response , or trackback from your own site.

3 commentsAdd your comment
  1. It’s posts like this that keep me coming back and checking this site regularly, thanks for the info!

  2. Nice brief and this fill someone in on helped me alot in my college assignement. Thank you for your information.

  3. Pura Wank says:

    I was just searching for this info for some time. After 6 hours of continuous Googleing, finally I got it in your website. I wonder what is the lack of Google strategy that don’t rank this type of informative websites in top of the list. Generally the top web sites are full of garbage.

 

Leave a Reply