Change .php to .html using .htaccess or httpd.conf
Posted on September 15th, 2006 | Subscribe in a Reader | Subscribe by Email
It is common that when a site already has so many html pages, it is converted to php/asp to make it database driven so it’ll be easier to manage. But the problem is that some pages are already bookmarked, linked by other sites, and have a good Google Page Ranking.
If a site is converted to php, the html page is lost and you will be seeing a lot of 404 reposts on your stats. There are many ways to solve this problem, but for this article we will be manipulating the server settings to allow php database driven sites to appear as html, thus preventing any error 404 on your site.
http://alfredo.palconit.com/archives/php-to-html-using-htaccess-httpdconf.html
is different from
http://alfredo.palconit.com/archives/php-to-html-using-htaccess-httpdconf.php
Here are the basics. When you save a file as .php the server will see it as a php file. When you save a file as .html, the server will treat it as a regular html file. But when you write php codes on a file and save it as .html, the server will still treat it as an html file and the php code will appear in the html source code, and php functions wont work, unlike when you save it as .php, the php codes will not appear in the browser and the php code will function.
To make your .php file to appear as .html on a browser, you will need to change either the http.conf settings of your Apache Server or create/update your .htaccess file if you don’t have access to the Apache Server configuration file.
Here is how to update your httpd.conf:
AddType application/x-httpd-php .php .html
Notice the ‘.html’ added in the line. This means the server will see .html files as .php.
If you don’t have access to httpd.conf, make the changes in .htaccess by adding this line of code:
AddType application/x-httpd-php .php .html
Make use you save it as .htaccess (notice the ‘.’ before .htaccess) and must be located on the folder where your pages are.
Disclaimer: I haven’t actually tried this one but maybe this will work. I am not responsible if your PC will catch fire if you make these changes. Please post a comment if you’ve tried it to work.
Update: Here is what I used on one of my client’s site wanting a php file to have an .html extension.
RewriteEngine on
RewriteRule (.*)\.html$ index.php?page=$1
the effect would be
http://www.palconit.com/index.php?page=test
can now be viewed as
http://www.palconit.com/test.html