AddHandler vs AddType : Apache Directive

Just from last few days while stumbling on the web for Branding a website, I came across something called as ‘Using custom extensions to brand your website’. Topic was quite interesting hence I tried to implement it. In first implementation, I got an error and I found that Apache is not serving file properly. Rather than executing file at the server, Apache send it to browser as it is and which results into download of the file at My PC. Again when I started digging more in this topic, I found something new called as Apache Directives. A directive defines how a file will be treated by Client or Server. The error was related to directives, I got answer to my question, I changed my directives and everything started working fine.

AddHandler and AddTypes are two directives which define how file will be treated by apache. Proper use of them will result into desired output while improper use may break server and can result into security risk also.

AddHandler vs AddType

AddHandler and AddType have a huge different meaning. Basically AddHandler is used if we want to handle files at server and AddType is used if we want to handle files at the browsers. Some file types like php, asp must handle at server and not at user browser, hence we will use AddHandler with them. That’s if you are developing a ruby on rail or PHP app then you should use AddHandler directive since they must get parsed at server only. While some file type like html, js etc must handled at user’s browser hence we will use AddType directive with them.

In Short…

AddType defines how a client (example A web browser) should deal with the file (or data stream), while AddHandler defines how a server should parse a file.

Strict versus quirks modes of web browsers

This is slightly related to how browsers actually deal with the content type you set in your AddType directive. Some browsers like Firefox who follows the standard and not tries to guess mime, will handle a file according to the content type in your Apache configuration. So if you wrongly assigned the text/plain content type to image then all images will displayed as text while on other hand Internet Explorer is more flexible in this case. Unlike Firefox, Internet Explorer tries to guess the mime type for misconfigured mime types and try to show a proper content at their place.

More Information:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.