Forum Moderators: open
# Deny all
SetEnvIf Remote_Addr .* dont_allow
# Allow some IP ranges
SetEnvIf Remote_Addr ^(?:66\.249\.(?:6[4-9]|[78][0-9]|9[0-5])|74\.125)\. !dont_allow
# Allow global access to certain pages
SetEnvIf Request_URI ^/robots\.txt$ !dont_allow
SetEnvIf Request_URI ^/main-page\.php$ !dont_allow
<Files *>
Order Allow,Deny
Allow from all
Deny from env=dont_allow
</Files>
RewriteCond %{ENV:dont_allow} ^1$
RewriteRule .* - [F] SetEnvIf Remote_Addr ^(?:66\.249\.(?:6[4-9]|[78][0-9]|9[0-5])|74\.125)\. allow
<Limit GET POST>
Order Deny,Allow
Deny from all
Allow from env=allow
</Limit> Thanks wilderness. You can use a Limit container. If you want to use mod_rewrite instead, you could use:
RewriteCond %{ENV:dont_allow} ^1$
RewriteRule .* - [F]
SetEnvIfNoCase User-Agent (google|msn|bing)bot dont_allow
SetEnvIf From ^googlebot\(at\)googlebot\.com$ !dont_allow
SetEnvIf From ^bingbot\(at\)microsoft\.com$ !dont_allow
SetEnvIf Request_URI ^/robots\.txt$ !dont_allow
RewriteCond %{ENV:dont_allow} ^1$
RewriteRule .* - [F]
RewriteCond %{ENV:dont_allow} ^1$
RewriteRule .* - [F]
Have you ever thought about using the HTTP_FROM header? I've never seen it spoofed or used from a specified IP range from a non-crawler. It also simplifies the solution in your case.
SetEnvIfNoCase User-Agent (google|msn|bing)bot dont_allow
SetEnvIf From ^googlebot\(at\)googlebot\.com$ !dont_allow
SetEnvIf From ^bingbot\(at\)microsoft\.com$ !dont_allow
SetEnvIf Request_URI ^/robots\.txt$ !dont_allow
RewriteCond %{ENV:dont_allow} ^1$
RewriteRule .* - [F]
SetEnv dont_allow 1)
How would I add the following lines into the ENV?
SetEnvIfNoCase User-Agent googlebot google_ua
SetEnvIfNoCase User-Agent (bingbot|msnbot) msn_ua
SetEnvIf Remote_Addr ^66\.249\.(6[4-9]|[78][0-9]|9[0-5])\. google_ip
SetEnvIf Remote_Addr ^65\.5[2-5]\. msn_ip
SetEnvIf Remote_Addr ^70\.37\. msn_ip
SetEnvIf Remote_Addr ^157\.[45][0-9]\. msn_ip
SetEnvIf Remote_Addr ^207\.46\. msn_ip
SetEnvIf Remote_Addr ^207\.[67][0-9]\. msn_ip
RewriteCond %{ENV:google_ua} ^1$
RewriteCond %{ENV:google_ip} !^1$
RewriteRule !^robots\.txt$ - [F]
RewriteCond %{ENV:msn_ua} ^1$
RewriteCond %{ENV:msn_ip} !^1$
RewriteRule !^robots\.txt$ - [F]