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
Great tutorial. Got a question that I can’t seem to get solved about this. I was going to add an rss feed via php from a third party website to my website. It works every way except through php. Using PHP nothing shows up. I’ve asked my host, which they told me to add the
AddHandler application/x-httpd-php5 .html .htm .php
to my .htaccess file. I did that and still nothing. I’ve asked different third party rss people and they say ask my host. My host says they are not programmers so sucks for you.
Any ideas what could be causeing this? Its a very simple line of code:
thanks
-Mr.Concept
What section would your html page would you put this code?
how to run php in html file?
—————
1. – determine which php version running on your server
2. – determine configuration of Apache PHP Handler, is it dso or cgi or SuPHP
dso – mean that php run as Apache module.
cgi or SuPHP – php run as a CGI module.
3. – add to .htaccess
for dso(php as Apache module)
AddType application/x-httpd-php .htm .html
for SuPHP, if your server run php4
AddType application/x-httpd-php4 .htm .html
or
AddType application/x-httpd-php5 .htm .html
if your server run php5
for CGI , add to .htaccess line
AddHandler application/x-httpd-php .html .htm
or
AddHandler application/x-httpd-php5 .html .htm
————————————–
AddType application/x-httpd-php(x) – for php as Apache module, Dso. x – php version
AddHandler application/x-httpd-php(x) – for php as CGI. x – php version
Thanks , it really works and very helpful..
doesn’t work on my site.