This site runs best with JavaScript enabled.

HTML Files Parsed Through PHP

Photo by Chris Lao on Unsplash

How to pass .html files through the PHP parser with Apache

In the past I have used mod_rewrite to redirect .html file request to the equivalent .php file names. For example:

1RewriteRule (.+)\.html? $1.php

The above code would redirect any page name page.htm or page.html to page.php.

But what if you had .html or .htm file that you actually wanted to run through the php processor? Try this in your .htaccess file:

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

Discuss on TwitterEdit post on GitHub

Share article
Dustin Davis

Dustin Davis is a software engineer, people manager, hacker, and entreprenuer. He loves to develop systems and automation. He lives with his wife and five kids in Utah.

Join the Newsletter

Dustin Davis