Normally, a PHP code can only be inserted on a PHP file. If your website is in HTML, then you have to convert all your “.html files” into “.php” in order to be able to embed PHP codes. If you have 1-page or 3-page website, that is not such a hassle to do. However, when you have a large html-based website, that becomes a big problem and a major headache!
Well, here’s an alternative solution that you might like! You no longer need to convert your html site into PHP — thus, eliminating the hassle. You can now use your regular html site as it is and make it behave as if it was a PHP-based website so that you can embed PHP codes on your pages. For example, you can finally add RSS feeds on your html page so that you can have new and fresh content everyday on your website.
How is this possible? This method only works if your server supports .htaccess. If you are unsure if htaccess is supported on your server, contact your web hosting provider.
(1) First, open notepad and create a new text file.
(2) Enter the following on the document:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .html .htm
(3) Save the file as “htaccess.txt” (txt is the default extension of a file made by Notepad program on your PC).
(4) Upload this file unto your server.
(5) Rename the file as “.htaccess”
(6) Insert the PHP code into the html page that you want it on
(7) Enjoy better features on your site!
Hope this information helped you.
If you need any other type of assistance with your online projects, contact me with your requirements. If it’s within my scope, I’ll respond with a price quote accordingly.
this causes the php page to attempt to download instead of display.
Another option is to use a rewrite rule via htaccess to have the .html file read as a .php
I assume that the PHP is still processed on the server?
I cant understand about htaccess in what should i rename it (.htaccess) or (htaccess.htaccess)
The full file name, when everything is done will be: .htaccess
Thanks a million for this tutorial. Im building a massive eCommerce site using PHP and MySQL where the requirement was that each product item page should be a static html fite. This posed a major development challenge because i needed to run dynamic php code on all pages – to retrieve and display a snapshot of the ShoppingCart Session (Total Balance, Number of Items added) So you can imagine the challenge there. After 7 years of PHP programming I didn’t realise I could infact embed PHP code in a .html file. If you had a donate button I would have donated something.
Again, Thank You