Rewrite .php extension with .html using .htaccess | URL rewriting using .htaccess.
anoopsachari | Aug 21, 2010 | Comments 3
I had to implement URL rewriting in my last project . After some browsing found that it can be implemented using .htaccess file .
Ok fine . we can start from the basics of creating a .htaccess file .
In windows one cannot create .htaccess file directly . You can either create a “htaccess” file on windows upload it and rename it to “.htaccess” or create a notepad file and save it as “.htaccess” file .
Begin Rewriting
Whenever you use mod_rewrite (the part of Apache that does all this magic), you need to do
Options +FollowSymlinks RewriteEngine on
before any ReWrite rules. note: +FollowSymLinks must be enabled for any rules to work, this is a security requirement of the rewrite engine. Normally it’s enabled in the root and you shouldn’t have to add it, but it doesn’t hurt to do so, and I’ll insert it into all the examples on this page, just in case*.
The next line simply switches on the rewrite engine for that folder. if this directive is in you main .htaccess file, then the ReWrite engine is theoretically enabled for your entire site, but it’s wise to always add that line before you write any redirections, anywhere.
Simple Rewriting
You can rewrite all .php files with .html tag . Use following code to implement the same .
Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.html $1\.php
Now try .html with .php extension . ie , help.html would call help.php .
About the Author: a holistic web developer , movie buff and technical blogger from queen of arabian sea.







I tried this on my web site , But won’t work well need to do anything on cpanel
@faisal no need to change anythng on cpanel.
Hi,
I try to rewrite url’s programetically, the url update into the database as well as in .htaccess but when click on updated link I got ’404 file not found Exception.’
My code is
RewriteEngine On
RewriteRule ^\”oldpath\”/ newpath [R]
I don’t know, what should I do?
Please help