Redirecting user on different pages depending cookies

By | August 26, 2009

When you need to redirect a visitors to different pages depening on a value from a cookie you can use this code:

RewriteCond %{HTTP_HOST}  ^mydomain.com$
RewriteCond %{HTTP_COOKIE} !MyDomainCookie
RewriteRule  ^/$           /first-page.htm  [R=301,L]
RewriteCond %{HTTP_HOST}  ^mydomain.com$
RewriteCond %{HTTP_COOKIE} MyDomainCookie=Value1
RewriteRule ^/$ /second-page.htm [R=301,L]
RewriteCond %{HTTP_HOST}  ^mydomain.com$
RewriteCond %{HTTP_COOKIE} MyDomainCookie=Value2
RewriteRule ^/$ /third-page.htm [R=301,L]
RewriteCond %{HTTP_HOST}  ^mydomain.com$
RewriteCond %{HTTP_COOKIE} !MyDomainCookie
RewriteRule  ^/$           /first-page.htm  [R=301,L]
RewriteCond %{HTTP_HOST}  ^mydomain.com$
RewriteCond %{HTTP_COOKIE} MyDomainCookie=Value1
RewriteRule ^/$ /second-page.htm [R=301,L]
RewriteCond %{HTTP_HOST}  ^mydomain.com$
RewriteCond %{HTTP_COOKIE} MyDomainCookie=Value2
RewriteRule ^/$ /third-page.htm [R=301,L]

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.