有条件地设置 X-Frame-Option

Conditionally set X-Frame-Option

我正在尝试使用基于 apache HTTP Server 2.2.32 的 IBM HTTP Server (IHS) 8.5.5.12 设置 X-Frame-Options。

我尝试过使用 SetEnvIf,但不知道如何比较 httpd.conf 文件中的环境变量。

我已经在 IHS 9 中使用 If 条件尝试过相同的方法并且它有效,但不知道如何在 IHS 8.5.5.12 中实现相同的方法

<IfModule mod_headers.c>
    <If "%{HTTP:X-Requested-From} == 'mobileapp'">
        Header unset X-Frame-Options
    </If>
    <Else>
        Header set X-Frame-Options SAMEORIGIN
    </Else>
</IfModule>

以上代码在 IHS 9 中运行良好,有人可以帮忙吗?

此致
穆罕默德阿什法克

这里的技巧是 Header 指令在 Apache 2.2 中可以是有条件的,但只能在环境变量上。但是 SetEnvIf 先运行,可以根据请求头设置环境变量:

SetEnvIf X-Requested-From mobileapp is_mobile=1
Header set X-Frame-Options SAMEORIGIN
Header unset X-Frame-Options env=is_mobile


$ wget -qS  http://localhost 2>&1 |grep X-F   X-Frame-Options:
SAMEORIGIN 
$ wget -qS  --header="X-Requested-From: mobileapp"
http://localhost 2>&1 |grep X-F 
$