Running PHP code in a file with an .html extension

Overview

Normally, when PHP and HTML are combined in the same file, the file uses a .php extension and displays data in the browser.

However, if you need to place PHP code in a file with an .html extension, you must add a Handler to your .htaccess file.

Code to add to your .htaccess file

View the following articles for instructions on how to edit files using an FTP or SSH client.

The file you need to add code to is named .htaccess. If this doesn't exist in your website's home directory, use the articles above to create it. Add the following line to the .htaccess file.

AddHandler php-cgi .html

This line of code allows files with .html extensions to run PHP code in your browser.

Did this article answer your questions?

Article last updated PST.