Reputation: 5456
I am learning htaccess. Is the following possible by using htaccess:
1) Block every visitor/IP to site.
2) Block all the bots except google bot.
RewriteEngine On
order deny,allow
deny from all
RewriteCond %{HTTP_USER_AGENT} (bingbot|Baiduspider) [NC]
RewriteRule .* - [R=403,L]
Is the above htaccess right? Any help would be appreciated.
Upvotes: 0
Views: 1910
Reputation: 96454
Is the above htaccess right?
No, of course it isn’t right – because you are blocking all requests with
order deny,allow
deny from all
– so the Google bot won’t get access either.
You can do this by using a combination of SetEnvIf
and Allow
– see http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow, that has an example for exactly this.
(You’ll need to remove the Directory
directive used in there, because that can’t be used in .htaccess files. But only those two lines, what is inside the directive you have to keep of course.)
Upvotes: 0