这里的诀窍是
Header
指令在Apache2.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
$