Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
960 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...