2

希望有人可以帮助解决这个问题。

我有以下代码检查访问者的用户代理并引发错误

# ANYWHERE IN UA
RewriteCond %{HTTP_USER_AGENT} ^.* (exabot|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]

# SERVE ERRORDOCUMENT
RewriteRule . - [F,L]

ErrorDocument 500 /errorPage500.php

由于某种我不知道的原因,错误文档失败并出现以下错误

禁止的

您无权访问此服务器上的 /。

此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。

我是否需要添加更多代码才能使其正常工作?

提前致谢

完整代码如下

RewriteEngine On
#prevent hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?website.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

# Redirect from website.com to www.website.com
RewriteCond %{HTTP_HOST} ^ website.com [NC]
RewriteCond %{HTTP_HOST} !^m.website.com [NC]
RewriteCond %{REQUEST_URI} !errorPage
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1  [R=301,L]


ErrorDocument 400 /errorPage400.php
ErrorDocument 401 /errorPage401.php
ErrorDocument 403 /errorPage403.php
ErrorDocument 404 /errorPage404.php
ErrorDocument 500 /errorPage500.php

php_value session.gc.maxlifetime 604800
php_flag register_globals 0
php_flag session.use_only_cookies 1
php_flag session.use_trans_sid 0


<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css

#The following line also enables compression by file content type, for the following list of Content-Type:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml

#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule>

<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>

<filesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
# 1 WEEK
<filesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=604800, proxy-revalidate"
</filesMatch>
# 1 MIN
<filesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</filesMatch>

RewriteBase /

# IF THE UA STARTS WITH THESE
RewriteCond %{HTTP_USER_AGENT} ^(aesop_com_spiderman|alexibot|backweb|bandit|batchftp|bigfoot) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(black.?hole|blackwidow|blowfish|botalot|buddy|builtbottough|bullseye) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(cheesebot|cherrypicker|chinaclaw|collector|copier|copyrightcheck) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(cosmos|crescent|curl|custo|da|diibot|disco|dittospyder|dragonfly) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(drip|easydl|ebingbong|ecatch|eirgrabber|emailcollector|emailsiphon) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(emailwolf|erocrawler|exabot|eyenetie|filehound|flashget|flunky) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(frontpage|getright|getweb|go.?zilla|go-ahead-got-it|gotit|grabnet) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(grafula|harvest|hloader|hmview|httplib|httrack|humanlinks|ilsebot) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(infonavirobot|infotekies|intelliseek|interget|iria|jennybot|jetcar) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(joc|justview|jyxobot|kenjin|keyword|larbin|leechftp|lexibot|lftp|libweb) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(likse|linkscan|linkwalker|lnspiderguy|lwp|magnet|mag-net|markwatch) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(mata.?hari|memo|microsoft.?url|midown.?tool|miixpc|mirror|missigua) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(mister.?pix|moget|mozilla.?newt|nameprotect|navroad|backdoorbot|nearsite) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(net.?vampire|netants|netcraft|netmechanic|netspider|nextgensearchbot) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(attach|nicerspro|nimblecrawler|npbot|octopus|offline.?explorer) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(offline.?navigator|openfind|outfoxbot|pagegrabber|papa|pavuk) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(pcbrowser|php.?version.?tracker|pockey|propowerbot|prowebwalker) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(psbot|pump|queryn|recorder|realdownload|reaper|reget|true_robot) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(repomonkey|rma|internetseer|sitesnagger|siphon|slysearch|smartdownload) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(snake|snapbot|snoopy|sogou|spacebison|spankbot|spanner|sqworm|superbot) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(superhttp|surfbot|asterias|suzuran|szukacz|takeout|teleport) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(telesoft|the.?intraformant|thenomad|tighttwatbot|titan|urldispatcher) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(turingos|turnitinbot|urly.?warning|vacuum|vci|voideye|whacker) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(libwww-perl|widow|wisenutbot|wwwoffle|xaldon|xenu|zeus|zyborg|anonymouse) [NC,OR]

# STARTS WITH WEB
RewriteCond %{HTTP_USER_AGENT} ^web(zip|emaile|enhancer|fetch|go.?is|auto|bandit|clip|copier|master|reaper|sauger|site.?quester|whack) [NC,OR]

# ANYWHERE IN UA
RewriteCond %{HTTP_USER_AGENT} ^.*(exabot|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]

# ISSUE 403 / SERVE ERRORDOCUMENT
RewriteRule . - [F,L]

#when access is denied, allow access to just the error page and logo
<Files errorPage.*> 
Order Deny,Allow 
Allow from All 
</Files>
<Files  logo.gif>
Order Deny,Allow 
Allow from All
</Files>
4

3 回答 3

2

尝试将您的代码更改为:

ErrorDocument 400 /errorPage400.php
ErrorDocument 401 /errorPage401.php
ErrorDocument 403 /errorPage403.php
ErrorDocument 404 /errorPage404.php
ErrorDocument 500 /errorPage500.php

# all of your %{HTTP_USER_AGENT} 
# matches here
# ...
# ANYWHERE IN UA
RewriteCond %{HTTP_USER_AGENT} "exabot|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures" [NC]
# SERVE ERRORDOCUMENT conditionally
RewriteRule (?!^errorPage403\.php$)^ - [F,L]
于 2013-04-15T09:03:47.597 回答
1

部分代理禁止访问,所以禁止消息是正常的。没有 403 错误处理程序脚本,这就是生成 500 错误的原因。

如果您希望脚本处理 403 错误,则必须添加它,因为 [F] 标志会导致服务器返回 403 Forbidden 状态码。

如果是这种情况,请创建errorPage403.php脚本并尝试以下操作:

RewriteEngine On
# ANYWHERE IN UA
RewriteCond %{HTTP_USER_AGENT} ^(exabot|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) [NC]
# SERVE ERRORDOCUMENT
RewriteCond %{REQUEST_URI}  !/errorPage403.php [NC]
RewriteRule . - [F]

ErrorDocument 500 /errorPage500.php
ErrorDocument 403 /errorPage403.php

更新

根据对此答案的OP评论和问题更新,解决方案是在我的评论中建议的规则之前添加一个条件,并从一开始就在此答案中,如下所示:

# Add next line
RewriteCond %{REQUEST_URI} !/errorPage403.php [NC] 

# To current rule in your file.
RewriteRule . - [F,L].
于 2013-04-15T11:24:53.627 回答
0

你已经得到它抛出 500 错误。注意:

ErrorDocument 500 /errorPage500.php
于 2013-04-15T09:11:01.590 回答