Execute PHP from a .html File
Wednesday May 17, 2006
Usually when we run PHP, we put it in a file with a .php extension. Sometimes however, we need to execute PHP code on a .html page. The easiest way would be to simply rename the page from yourfile.html to yourfile.php. This however can cause problems if the page has been around awhile and has lots of incoming links, or is already ranked in search engines, and you don't want to change it's name.
The solution is to modify the .htaccess file to make PHP executable on .html files. By doing this you can make all your .html/.htm files run PHP, or you can set it to simply process one specific page (yourpage.html for example) as PHP.
Some hosting companies also allow you to change this setting from your control panel, or if you contact them they may be able to change this setting for you.
The solution is to modify the .htaccess file to make PHP executable on .html files. By doing this you can make all your .html/.htm files run PHP, or you can set it to simply process one specific page (yourpage.html for example) as PHP.
Some hosting companies also allow you to change this setting from your control panel, or if you contact them they may be able to change this setting for you.


This is a good idea to hide the languages we use in order to run our dynamic websites!
Thanks
I must have missed something. I added the necessary 2 lines of code to my .htaccess file, and inserted the DATE function into the page linked here. But it’s still not displaying.
Just do it the standard way: 301 redirect with .htaccess
Redirect 301 /page.html http://www.example.com/page.php
This will make google reindex the page (so new users will be looking at the correct page) and old users bookmarks will stay working.
I do not consider having php parse some html files to be good practise and I advise against it.
Great idea. But if you need to change the filetype of a page, you can simply wipe your old page and put a JavaScript redirect on it.
CoDE