Need some htaccess

blazen

Regular Member
Joined
Mar 8, 2008
Messages
476
Reaction score
148
I need some help with htaccess. I tried to code a htaccess that will that will allow search engine visitors and bots, and redirect everyone else. My problem is when the visitor is a bot or not from the search engines, the site seems be caught in a loop

Basically what I want htaccess to do:

-htaccess sees the referrer is from a search engine and the visitor will be redirected to a linkA.

-If visitor is not from a search engine, the htaccess checks if the visitor is a bot, if so the bot will be able to crawl the site.

- if visitor do not have a search engine referrer and is not a bot, the visitor will be redirected to linkB.

Here is what I wrote in My htaccess

Code:
RewriteBase /
#
#First redirect any visitors from search engines to url
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^.*yahoo.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*google.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*msn.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*live.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*ask.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*aol.*$
RewriteRule ^.*$ http://www.linkA.com [R,L]
#
#Now allow specific bots, and redirect everyone else
RewriteCond %{HTTP_USER_AGENT} !^googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} !^slurp [OR]
RewriteCond %{HTTP_USER_AGENT} !^Yahoo-MMCrawler [OR]
RewriteCond %{HTTP_USER_AGENT} !^msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} !^SandCrawler [OR]
RewriteCond %{HTTP_USER_AGENT} !^Teoma [OR]
RewriteCond %{HTTP_USER_AGENT} !^Jeeves
RewriteRule ^.*$ http://www.linkB.com [R,L]
 
Last edited:
written from the memory - I didn't test it

Code:
RewriteBase /
RewriteEngine on

RewriteCond %{HTTP_REFERER} (yahoo) [NC,OR]
RewriteCond %{HTTP_REFERER} (google) [NC,OR]
RewriteCond %{HTTP_REFERER} (msn) [NC,OR]
RewriteCond %{HTTP_REFERER} (live) [NC,OR]
RewriteCond %{HTTP_REFERER} (yahoo) [NC,OR]
RewriteCond %{HTTP_REFERER} (ask) [NC,OR]
RewriteCond %{HTTP_REFERER} (aol) [NC]
RewriteRule ^.*$ http://www.linkA.com [R,L]

RewriteCond %{HTTP_USER_AGENT} !^googlebot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !^slurp [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !^Yahoo-MMCrawler [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !^msnbot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !^SandCrawler [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !^Teoma [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !^Jeeves [NC]
RewriteRule ^.*$ http://www.linkB.com [R,L]
 
Cyklotrial, your htaccess looks similar to mine except the [NC] part. I didn't try your htaccess yet, but can you explain what NC is for? (I'm still pretty new to writing htaccess)

EDIT: I think I understand that it is for case insensitive
 
Last edited:
Back
Top