AddHandler vs AddType are still valid, but modern server setups (NGINX, Apache 2.4+, PHP-FPM) may handle MIME types differently than described here.
Just the other day, while stumbling around the web looking into website branding techniques, I came across something called using custom extensions to brand your website. The topic was interesting enough that I decided to try it myself. My first attempt threw an error — Apache was sending my file straight to the browser as a download instead of executing it server-side. That sent me down a rabbit hole and I landed on something called Apache Directives.
A directive controls how a file is treated by either the client or the server. Once I understood which directive I was supposed to be using, everything started working fine.
AddHandler and AddType are the two directives you’ll deal with most when it comes to file handling. Using the wrong one can break your server or create a security risk.
AddHandler vs AddType
These two directives have very different meanings.
AddHandler is used when you want a file to be processed on the server. PHP, ASP, Ruby on Rails — any server-side language should use AddHandler because those files must be parsed by the server before anything reaches the browser.
AddType is used when you want the browser (client) to handle the file. HTML, JavaScript, CSS — these get sent as-is, so the browser needs to know what type of content it’s dealing with.
In short
AddType defines how a client (like a web browser) should deal with a file or data stream, while AddHandler defines how the server should parse it.
Strict versus quirks modes in browsers
This is slightly related to how browsers deal with the content type you set via AddType. Firefox follows the standard strictly — if you accidentally assign text/plain to an image, Firefox will display it as raw text. Internet Explorer is more forgiving and tries to guess the correct MIME type when something’s misconfigured, often rendering content correctly anyway.
More information: