Parse HTML as PHP using HTACCESS File

Sometimes, you are required to parse HTML web pages as PHP. 

Suppose you have older HTML web pages and are required to add some additional functionality that a programming language like PHP can only achieve.

Will you modify each web page manually and add PHP code? 
This can be a little impractical and monotonous, so you can parse HTML web pages as PHP using the .htacccess file to avoid this exercise. 

All you need to do is, locate the .htaccess file, add one of the following lines below, according to your setup and save the file.

a. If your web server is using suPHP, add the following line in .httaccess –  

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

b. If Apache is executing PHP as CGI, use the following – 

AddHandler application/x-httpd-php5 .html .htm

c. If your server is using PHP5, try the following –  

AddType application/x-httpd-php5 .html .htm
AddHandler application/x-httpd-php5 .html .htm

If nothing works, try one of the following – 

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
<FilesMatch "\.html$">
ForceType application/x-httpd-php
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .HTML


Was this answer helpful?

« Back