Mark Baker Posted March 31, 2009 Share Posted March 31, 2009 I'm trying to create a rewrite rule based on the value of a cookie rather than simply whether one is set or not. The following code tests for the existence of the cookie IRISVersion, which (if it exists) will contain either an empty string, or the name of a subdomain (e.g. 'subdomain1.','subdomain2.'). %{HTTP_HOST} is 'mydomain.com' The intent is to redirect to subdomain1.mydomain.com, subdomain2.mydomain.com or mydomain.com as appropriate. RewriteEngine on RewriteCond %{HTTP_COOKIE} CodeVersion RewriteRule /* http://%{HTTP_COOKIE}%{HTTP_HOST}/subdomainTest.html [R,L] However, the rewrite rule is picking up the value of all cookies set, and substituting in the entire set of values for the redirect. So I'm getting a redirect to http://codeversion=subdomain1./;%20login=truemydomain.com/subdomainTest.html I need some way to extract the actual value of the CodeVersion cookie for the rewrite rule, ignoring any other cookies that might be set. I suspect I'll probably need some for of regexp Alternatively, might a rewritemap provide an alternative solution Using Apache 2.2.6 Any help gratefully appreciated Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted March 31, 2009 Author Share Posted March 31, 2009 I've modified my cookie so that the empty string is no longer valid, so the CodeVersion cookie should now always contain a valid subdomain name, if it exists Alternative version of the mod_rewrite, trying to extract the cookie value in the rewrite condition RewriteCond %{HTTP_COOKIE} CodeVersion=([a-z0-9]+) RewriteRule /* http://$1%{HTTP_HOST}/subdomainTest.html [R,L] Still feel like I'm getting nowhere, other than into an infinite loop of redirection Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted March 31, 2009 Author Share Posted March 31, 2009 Current version: RewriteEngine on RewriteCond %{HTTP_COOKIE} IRISVersion=([^;]+) [NC] RewriteRule /* http://%1%{HTTP_HOST}/domain.html [R=301,L] seems to be partially working, but I seem to be getting some issues with cached pages Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.