Change file extension in URL

In my previous article I have shown how you can use different extension of a file instead of .php explicitly but in this post I have explain how to rewrite the URL instead of renaming the file extension explicitly.

To rewrite the URL you must add following lines in a .htaccess file and place it to root directory of your application.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*).htm$ $1.php [nc]

The above code will rewrite the product.php to product.html.

And following is the code to pass parameters with URL

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*).html(.*)$ $1.php$2

Some related posts:

1 Comment

Leave a Comment