Html http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" ... 把它放在 .htaccess 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7567661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:49:09  来源:igfitidea点击:

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

apachehtml.htaccessgoogle-chrome-frame

提问by Tallboy

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

我下载了 html5 样板文件,但它不会在标题中使用它进行验证。

<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.

我被告知我可以将它添加到 .htaccess 以获得相同的效果以避免验证错误。

<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. 我如何测试以确保它正常工作
  2. filesmatch 参数有什么作用?我应该修改它还是原样很好?

回答by Giroin

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

尝试通过 web.config 或 htacess 文件传递​​它

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.

您的页面将在此之后有效。对不起,我不是一个 php 人。

回答by tzi

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

我发现的最好的 htaccess 配置如下:

<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.

因为它只为 IE 浏览器发送标头。

回答by Ayman Bedair

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

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 :)

Aaron Layton 听到了这一切:) 只需向下滚动到“修复”并跳过以上所有内容:)

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

或者您可以将它添加到您的 .htaccess 文件中,如下所示:

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

回答by Quentin

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.

向 URI 发出请求并查看响应标头。有很多工具可以做到这一点,包括 Charles Proxy、Firebug 和 Chrome 开发者工具。

What does the filesmatch parameter do?

filesmatch 参数有什么作用?

It is described in the manual

在手册中描述