deflime
deflime

Reputation: 613

.htaccess: Check for cookie, if none, 301 redirect

Within .htaccess, is there a way to check for a cookie (doesn't even need to confirm the value, just the existence is fine)? If cookie: do nothing/load page.php; else 301 redirect.

Redirect 301 /page.php http://another-site.com

Here is where I'm at, stumbling a bit, work in progress.

RewriteRule ^page.php [NC,L]
RewriteCond %{HTTP_COOKIE} !cookie=123 [NC]
RewriteRule ^(.*)  http://new-site.com [NC,L]

Upvotes: 0

Views: 2608

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You can do it this way

RewriteEngine on

RewriteCond %{HTTP_COOKIE} !YourCookie=123 [NC]
RewriteRule ^page\.php$ http://new-site.com [R=301,L]

If your cookie (rename it as you want) does not contains 123 and url is /page.php then redirect to http://new-site.com

Upvotes: 1

Related Questions