You are here

用.htaccess屏蔽特定的ip,UA,扩展名,目录,文件名的访问,减少无效访问

基本都有备注了,按自己的实际情况修改一下
如果 修改后提示500错误的话 自己删掉一部分慢慢排查一下!
符合屏蔽条件的都跳到 http://cachefly.cachefly.net/100mb.test
这个下载100M的文件鸟!
主要是屏蔽一些非中文的搜索引擎
基本没给来流量的搜索引擎用robots屏蔽 还不按规矩来的 yahoo china bing jike搜索

#通过ip屏蔽
<Limit GET>
 order allow,deny
 allow from all
# 即刻搜索
deny from 1.202.221
# java
deny from 92.82.228.135
deny from 89.123.53.40
deny from 208.115.111
# yahoo
deny from 110.75.175
deny from 125.65.113.89
deny from 114.93.194.112
deny from 125.65.113.89
#bing
deny from 207.46
deny from 65.108.198
deny from 157.55
deny from 65.52
#purebot
deny from 85.17.29
 </Limit>
 
<IfModule mod_rewrite.c>
#根据ua(useragent)和几个非中文搜索引擎屏蔽的,前面2个的是完全匹配,后面是只要包含就咔嚓的
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Yottaa" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Wget" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "360space" [OR]
RewriteCond %{HTTP_USER_AGENT} "Slurp\ China" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MJ12bot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "jikespider" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Java" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Python" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Windows\ 98" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 5" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "purebot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Ezooms" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "bingbot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "msnbot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Purebot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AugustBot\/augstbot" [NC,OR]
#下面3个是抄别人的
RewriteCond %{QUERY_STRING} proc/self/environ [NC,OR]  
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [NC,OR]  
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [NC,OR]  
# RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]  
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]  
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ http://cachefly.cachefly.net/100mb.test [NC,L]

#根据后缀,或文件名屏蔽的
RewriteRule ((\.(asp|aspx|mdb|ini|jsp|sql|dll|do)$)|bencandy.php|about_us.html|neverexistsa|javascript|wp-|((zz|backup|base|databack|server|sql|web|www|www1)\.(rar|zip))|wwwroot)	http://cachefly.cachefly.net/100mb.test [R=403,NC,L]
# 根据目录屏蔽的
RewriteRule (--new|do|shopadmin|bbs|plus|plug|data|database|img|Games|gaoji|--manage|UploadSoft|dede|duty|gbook|Temp|image)/(.*)$ http://cachefly.cachefly.net/100mb.test [R=403,NC,L]

<FilesMatch "\.(rar|flv|engine|info|phps|fla||sh|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
Order allow,deny
deny from all
</FilesMatch>
</IfModule>

转帖的要厚道,给我加这个链接:用.htaccess屏蔽特定的ip,UA,扩展名,目录,文件名的访问,减少无效访问

收藏一个老外的:http://perishablepress.com/stupid-htaccess-tricks/

文章类型: 
关键字: