A fresh mix of code snippets and tutorials

Set X-UA-Compatible via .htaccess

It’s relatively well known that you can set X-UA-Compatible headers with HTML.. here is how to do it with a bit of .htaccess.

Let’s say you have this defined in the head section of your web pages:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

That method works fine, but it’s also possible to set X-UA-Compatible headers via .htaccess, which can help to decrease page load times and shave off a little bandwidth.

Just add the following slice to root .htaccess:

<FilesMatch "\.(htm|html|php)$">
	<IfModule mod_headers.c>
		Header set X-UA-Compatible "IE=Edge,chrome=1"

Of course you can change IE=Edge,chrome=1 to whatever is required. Compare with the HTML meta tag to better see what’s what. Also, remember to edit the FilesMatch directive to suit your needs.

Learn more

.htaccess made easy