http-equiv=“X-UA-Compatible” content=“IE=edge,chrome=1” … Putting this in .htaccess?

强颜欢笑 提交于 2019-12-17 23:36:52

问题


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?

回答1:


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.




回答2:


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.




回答3:


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>



回答4:


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



来源:https://stackoverflow.com/questions/7567661/http-equiv-x-ua-compatible-content-ie-edge-chrome-1-putting-this-in-hta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!