希望有人可以帮忙解决这个问题。
我有以下代码检查访问者的用户代理并抛出错误
# 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内部服务器错误错误。
我需要添加更多代码吗?
提前致谢
以下完整代码
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>
答案 0 :(得分: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]
答案 1 :(得分: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].
答案 2 :(得分:0)
你已经失去了500错误。请注意:
ErrorDocument 500 /errorPage500.php