http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" ... Putting this in .htaccess?
Asked Answered
C

4

10

I downloaded html5 boilerplate and it wouldnt validate with this in the header.

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

I was told I can add this to .htaccess for the same effect to avoid validation errors.

<IfModule mod_headers.c>
  Header set X-UA-Compatible "IE=Edge,chrome=1"
  # mod_headers can't match by content-type, but we don't want to send this header on *everything*...
  <FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|xpi|safariextz|vcf)$" >
    Header unset X-UA-Compatible
  </FilesMatch>
</IfModule>

My question is

  1. How do i test to make sure this is working properly
  2. What does the filesmatch parameter do? should i be modifying that or is that pretty good as-is?
Conservatoire answered 27/9, 2011 at 10:29 Comment(0)
P
13

Try to pass it through the web.config or htacess file

Web.Config

<httpProtocol>
  <customHeaders>
    <clear />
    <add name="X-UA-Compatible" value="IE=Edge,chrome=1" />
  </customHeaders>
</httpProtocol>

your page will be valid after that. Sorry I am not a php guy.

Portie answered 7/5, 2012 at 9:17 Comment(0)
G
7

The best htaccess configuration that I found is this one below:

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    BrowserMatch MSIE ie
    Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  </IfModule>
</IfModule>

Because it sends the header just for IE browsers.

Grandmotherly answered 28/2, 2013 at 17:12 Comment(2)
"Best" always quite depends on viewpoints. It is not best imho, for this does browser sniffing, and worst, on server side. Browser sniffing is not an 100% reliable solution. Some users obfuscate their browser, some corporate proxies may do the same, proxies may cache the answer and serve it back to other browsers, browsers evolves and future versions may no more be recognized, ...Brotherhood
Sure! I think in this case it's not a big deal, since the browser sniffing doesn't trigger a critical feature.Grandmotherly
B
4

http://www.validatethis.co.uk/tag/x-ua-compatible/

Aaron Layton has it all hear :) Just Scroll down to the "The fix" and skip all the above :)

Or you could add it to your .htaccess file like this:

<FilesMatch "\.(htm|html|php)$">
    <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
    </IfModule>
</FilesMatch>
Bruxelles answered 15/4, 2013 at 8:25 Comment(0)
I
2

How do i test to make sure this is working properly

Make a request to a URI and look at the response headers. There are plenty of tools to do that, including Charles Proxy, Firebug and Chrome Developer Tools.

What does the filesmatch parameter do?

It is described in the manual

Irbm answered 27/9, 2011 at 10:30 Comment(3)
Thanks! My next question is... I have added the following to forward www to non-www and it appears when I type www.domain.com into google or firefox, it still stays at www. Is this a just part of the browser or is it actually not working.Conservatoire
<IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] </IfModule>Conservatoire
To ask your next question, please use the ask question linkIrbm

© 2022 - 2024 — McMap. All rights reserved.