RewriteCond comparing two variables in Apache htaccess

前端 未结 1 1994
傲寒
傲寒 2021-01-21 20:19

I would like to have a rewritecond that gets true if two variables HTTP_ORIGIN and HTTP_HOST are equals. I tried



        
1条回答
  •  一向
    一向 (楼主)
    2021-01-21 20:59

    In RewriteCond you cannot use a variable on right hand side.

    You have to use it like this:

    RewriteCond %{HTTP_HOST}##%{HTTP:Origin} ^(.+)##http://\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.

    0 讨论(0)
提交回复
热议问题