User Tools

Site Tools


apache:configure:configure_apache_to_treat_files_with_html_extensions_as_if_they_are_php_files

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.
apache/configure/configure_apache_to_treat_files_with_html_extensions_as_if_they_are_php_files.txt · Last modified: 2023/07/17 11:06 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki