RewriteCond比较Apache htaccess中的两个变量 [英] RewriteCond comparing two variables in Apache htaccess
问题描述
如果两个变量 HTTP_ORIGIN <,我希望有一个
rewritecond
获得 true
/ code>和 HTTP_HOST
相等。我尝试过
I would like to have a rewritecond
that gets true
if two variables HTTP_ORIGIN
and HTTP_HOST
are equals. I tried
RewriteCond %{HTTP:Origin} ^http://%{HTTP_HOST}(/|$)
但是,尽管Netbeans具有句法颜色,但Apache似乎并未取代%{HTTP_HOST}
。我猜是因为
But despite Netbeans syntactic color, it appears that Apache is not replacing %{HTTP_HOST}
by its value. I guessed it because
RewriteCond %{HTTP:Origin} ^http://cnfr005554(/|$)
RewriteCond %{HTTP_HOST} =cnfr005554
Works。
所以我如何测试两个变量%{HTTP:Origin}
和%{HTTP_HOST}
等于? (是的,它是用于应用OWASP的指南来缓解XSRF)
So how can I test that the two variables %{HTTP:Origin}
and %{HTTP_HOST}
are equals? (and yes, it's for applying OWASP's guidelines to mitigate XSRF)
推荐答案
在 RewriteCond $ c中$ c>您不能在右侧使用变量。
In RewriteCond
you cannot use a variable on right hand side.
您必须像这样使用它:
RewriteCond %{HTTP_HOST}##%{HTTP:Origin} ^(.+)##http://\1(/|$)
这里使用定界符 ##
连接2个变量(可以是任何变量)。然后在RHS上,我们匹配并捕获 ##
之前代表 HTTP_HOST
的值。在使用向后引用 \1
##
之后,我们进行匹配。
Here are are joining 2 variables using a delimiter ##
(it can be anything). Then on RHS we match and capture value before ##
that represents HTTP_HOST
. After ##
using a back-reference \1
we do our matching.
这篇关于RewriteCond比较Apache htaccess中的两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!