Web Designer in Hastings

Coding: PHP


Parsing PHP in HTML pages

With a little tweek of the .htaccess file it is possible to use php codes from within your regular html pages. The pages will be parsed just as if they were native .php pages.

Edit the .htaccess file

Go to your website's root and look for the file named .htaccess. If it's not there, create a blank text file using NotePad or your favourite plain text editor and save it as .htaccess

Edit the .htaccess file by adding the following lines.

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Save and upload the .htaccess file to your webserver.

The .htaccess file only affects documents within its own folder and subfolders below. For example, putting this code in the root will affect all html files for the whole site, putting the code in a subfolder will only affect files and folders within that subfolder.

Alternatively...

Some hosts are set up differently (Heart Internet for example). If you find the above fails to work with your website, try this code in your .htaccess file instead. Replace .html with .htm if that is the extension you have used for your pages.

AddHandler cgi-script .html
SetEnv PHP_EXTENSION .html


Use PHP in HTML pages