Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

variables - Apache match {HTTP_HOST} in {HTTP_COOKIE}

I want to check if {HTTP_HOST} is in {HTTP_COOKIE} and if not redirect to one cookie value.

The cookie is correctly set with : (cookie name is DST_HOST)

 RewriteCond %{HTTP_COOKIE} !DST_HOST [NC]
 RewriteRule ^ - [CO=DST_HOST:%{HTTP_HOST}:mydom.x]

Now I'm struggling with the RewriteCond statement as we cannot compare two variables.

I can easily test if the cookie is set with :

RewriteCond %{HTTP_COOKIE} DST_HOST

But I cannot do the variable comparaison test. The idea would be something like :

RewriteCond %{HTTP_COOKIE} !DST_HOST=%{HTTP_HOST}

The right portion of the statement isn't evaluated we can only put static contents here.

I then tried with something found in Apache configuration guide :

RewriteCond expr "! %{HTTP_COOKIE} -strmatch '*%{HTTP_HOST}*'"

But it doesn't evaluate the variables (I'm running Apache 2.4, maybe this only works with Apache 2.5)

Any help would be greatly appreciated.

Kind regards, Jean-Damien

question from:https://stackoverflow.com/questions/65952258/apache-match-http-host-in-http-cookie

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the solution :

 RewriteCond %{HTTP_HOST}!!%{HTTP_COOKIE} !^(.+)!!(.*)1(.*)$

Wildcard must be used as {HTTP_COOKIE} can contains many cookies.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...