apache - How to test many cookies in .htaccess with mod_rewrite? -


i want make internal redirection based on value of 2 cookies use of htaccess/mod_rewrite. don't know how refer both values of tested cookies backreferences. here want do:

foo = value_of_cookie_foo bar = value_of_cookie_bar if (foo , bar) {   rewriterule ^(.*)$ mysite/foo/bar [r,l] } 

sadly, following code not work. because (according apache documentation) backreferences apply last rewritecond. first 1 not taken account.

 rewritecond %{request_uri} ^/whatever$  rewritecond %{http_cookie} cookie_foo=([^;]+) [nc]  rewritecond %{http_cookie} cookie_bar=([^;]+) [nc]  rewriterule ^(.*)$ mysite/%1/%2 [r,l] 

for cookie cookie_foo=foo; cookie_bar=bar; above code redirects http://mydomain.com/mysite/bar instead of http://mydomain.com/mysite/foo/bar.

should enclose testing of both cookies in 1 rewritecond? how?

you should reorder cookie values them both @ once:

rewritecond %{request_uri} ^/whatever$ rewritecond %{http_cookie} (^|;\s*)cookie_foo=([^;]+) rewritecond %2;%{http_cookie} ^([^;]+)(;\s*|[^;])+cookie_bar=([^;]+) [nc] rewriterule ^(.*)$ mysite/%1/%3 [r,l] 

this put cookie_foo value @ beginning cookie_bar value too.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -