How do I parse HTML files as PHP?

Updated 10 months ago by Josselyn Rodriguez

You can use the following directive in .htaccess to parse HTML files as PHP. The exact line that you need to add will be different for different servers, depending on exactly how Apache and PHP are installed and configured. But one of these lines (or sets of lines) should do the trick:

AddHandler x-httpd-php .html .htm 
AddHandler php-script .php .html .htm
# If the server is using PHP 5 use:
# AddHandler php5-script .php .html .htm
AddType application/x-httpd-php .htm 
AddType application/x-httpd-php .html
# If the server is using PHP 5 use:
# AddHandler application/x-httpd-php5 .html .htm

To verify that it works, make a file called phptest.html and put some PHP code into it. Here is some code you can use for testing:

echo "PHP is working.";

Upload phptest.html tothe server and access it via the browser. If the page displays "PHP is working", then you're all done; but if it displays the PHP code or nothing at all, then it didn't work and you'll need to try different lines in your .htaccess file.

Having trouble? Contact us and our team will be happy to help.

How did we do?

Powered by HelpDocs