Apache - Configure - Configure Apache to treat files with HTML extensions as if they are PHP files

Create (or edit) the .htaccess file.

.htaccess
AddType application/x-httpd-php .html

NOTE: This setup can also be added to the main Apache configuration file, httpd.conf.

  • The .htaccess file can be further customized to only make the configuration effective to one PHP file.

To setup only a limited number of html files, use the following format:

.htaccess
<files filename.html>
AddType application/x-httpd-php .html
</files>

NOTE: The <files>, <filesMatch>, and <location> directives can be used.

  • A .htaccess file can be created in any directory within the document root, and when present the containing folder and sub-folders will inherit the configuration defined in the .htaccess file.
  • Another .htaccess file can be created in a sub-folder, and it will override the configuration defined by the parent configuration.

NOTE: One downside of setting up a web server to use html extensions for PHP scripts is performance.

  • Every HTML file will run through the PHP parser, and it will have a minor performance impact which will not likely be noticeable.