我正在尝试在所有情况下使用 Apache 中的 mod_headers 设置标头,除了某个路径。我已经尝试了以下三种变体中的每一种,但它们似乎都不能正常工作以排除路径。在所有情况下,我都会获取所有请求的标头,包括与示例路径匹配的请求,例如:http ://example.com/charts/24_hour_commodity/450/300
<VirtualHost *:8200>
...
SetEnvIfNoCase Request_URI "^/charts/.*" frameallow
Header set X-Frame-Options SAMEORIGIN env=!frameallow
...
</VirtualHost>
或者:
<VirtualHost *:8200>
...
Header always set X-Frame-Options SAMEORIGIN
<LocationMatch "^/charts">
Header always unset X-Frame-Options
</LocationMatch>
...
</VirtualHost>
或者
<VirtualHost *:8200>
...
Header always set X-Frame-Options SAMEORIGIN
<Directory "/full/path/to/charts">
Header always unset X-Frame-Options
</Directory>
...
</VirtualHost>
#tried both with and without the 'always' in all configs
谁能帮我弄清楚为什么在第一个示例中设置了标题或在以下两个示例中未设置标题?任何一种可行的解决方案就足够了...
更新:在阅读了 Apache 网站上的处理顺序后,我尝试使用条件块。这些都不起作用:
<If "%{REQUEST_URI} =~ m#^/charts#">
Header unset X-Frame-Options
</If>
或者
SetEnvIfNoCase Request_URI "^/charts" frameallow
<If "reqenv('frameallow') == 1">
Header unset X-Frame-Options
</If>
所以,还是破了。一定是关于在处理中的某个点后没有触发的 Header 语句。或者他有条件的那些在主要的之前以某种方式触发并被覆盖。虽然找不到将其调试到根本原因的方法。