Custom File Extension Parsing with PHP and Apache

Attention: open in a new window. PDFPrintE-mail

( 2 Votes )

Sometime in web applications, you may feel inclined to have dynamic code in .css, .js, .htm or .html files. To get Apache to parse these types of files you can create an .htaccess file and use the ”AddHandler application/x-httpd-php” command followed by the extensions you would like to have parsed as php.  Depending on your Apache configuration, you may have to use  ”AddHandler application/x-httpd-php4” or ”AddHandler application/x-httpd-php5” for different versions.

 

 This can be used to parse .html as such:

AddHandler application/x-httpd-php .htm .html

You can also parse .asp files as .php (this of course will only allow you to give the illusion of running ASP… if you really want to use .asp with apache, use mod_mono) :

AddHandler application/x-httpd-php .asp

Another cool trick is to parse custom file extensions to give a unique feel to your website. For example, if I felt like doing a highly supervised search-and-replace on Joomla!, I could replace all of the PHP files on The Clever Geek with .tcg files and run them like so:

AddHandler application/x-httpd-php .tcg



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! Yahoo! Joomla Free PHP
Comments
Add New Search RSS
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

SEO by Artio