如何检查标头是否存在。我不想检查值是否不同“”我想检查它是否真的存在使用:
的RewriteCond
我如何在htaccess文件中执行此操作?
答案 0 :(得分:1)
您可以使用这样的条件来了解标头X-SomeHeader
是否存在:
RewriteEngine On
# block if request header X-SomeHeader doesn't exist
RewriteCond %{HTTP:X-SomeHeader} !^$
RewriteRule ^ - [F]
答案 1 :(得分:1)
@anhubhava的回答很有用,但逻辑反了!应该是:
RewriteEngine On
# block if request header X-SomeHeader doesn't exist
RewriteCond %{HTTP:X-SomeHeader} ^$
RewriteRule ^ - [F]
或相反的例子:
RewriteEngine On
# redirect foo to bar if request header X-SomeHeader exists
RewriteCond %{HTTP:X-SomeHeader} !^$
RewriteRule ^foo$ bar [L]
答案 2 :(得分:0)
试试这种方式
RewriteEngine On
# block if request header X-SomeHeader doesn't exist
RewriteCond %{HTTP:TID} ^.+$
RewriteRule ^ - [L]
RewriteRule ^ - [F]