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 Link to comment https://forums.phpfreaks.com/topic/151897-mod_rewrite-based-on-cookie-value-regexp-in-mod_rewrite/ 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 Link to comment https://forums.phpfreaks.com/topic/151897-mod_rewrite-based-on-cookie-value-regexp-in-mod_rewrite/#findComment-797636 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 Link to comment https://forums.phpfreaks.com/topic/151897-mod_rewrite-based-on-cookie-value-regexp-in-mod_rewrite/#findComment-797658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.