Using .htaccess to Parse HTML Files as PHP

October 10th, 2008

I receive this question quite frequently by readers who want to know how to configure Apache to treat HTML files as if they were PHP. Parsing HTML files as PHP can be quite handy if you have a current HTML site that you’re moving over to PHP and you don’t want to have to change URLs. It’s also quite simple to do. It only takes one line in your .htaccess file.

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

Adding this line to your .htaccess file will add a new MIME type your Apache configuration. This tells Apache to recognize any of the provided file extensions as PHP. You can add as many extensions as you like. Just keep separating them with spaces.

Keep in mind, that these settings will override your server defaults.

Please use the trackback link when linking to this post.

Related Posts:

Add to Technorati Favorites

Leave a Reply

.htaccess Apache article articles by Nilpo ASP ASP Free automation clipboard desktop Dev Shed docx drive Internet Explorer Microsoft PHP registry remove script scripting text tutorial tweak tweets Twitter UAC updates User Account Control VBS VBScript vista volume Windows Windows 7 Windows 2000 Windows Guru Windows Script Windows Script Host Windows Scripting Windows Vista Windows XP Word WScript wscript.exe WSH XP