Reputation: 25
I have created page that every new user is redirected to upon visit, it sets a cookie that allows access to the rest of my site. I want to add exception to this rule for some sites and their bots:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} http://www.site1.com [NC,OR]
RewriteCond %{HTTP_REFERER} http://www.site2.net [NC,OR]
RewriteCond %{HTTP_USER_AGENT} bot1 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} bot2 [NC]
RewriteRule .? - [S=1]
RewriteCond %{HTTP_COOKIE} !yes=1 [NC]
RewriteRule !^(script1.php|script2.php)$ script2.php [L]
</IfModule>
As you can see, if the cookie doesn't exist or !=1 every user is redirected to script2.php.
I wrote some exceptions, but sometimes it works, and sometimes it doesn't.
I've made an error somewhere, but i don't see it.
Can you help me with this? Thank you for you time.
Upvotes: 1
Views: 125
Reputation: 16825
I'd rather use [L]
instead of [S=1]
.
Secondly, I would do a external redirect to script2.php, so it's not cached (incorrectly). So use [R,L]
instead of just [L]
on your last rule.
Upvotes: 1