【发布时间】:2021-03-22 20:11:06
【问题描述】:
我有一个自定义 403 页面,当我想阻止特定页面时它可以工作,但当我想匹配特定 HTTP_REFERER 时它不起作用。
使用特定的 HTTP_REFERER,我得到了常规的 403,为了测试 HTTP_REFERER,我在另一个站点“mysite.com”上添加了一个指向该项目的链接,当我点击该链接时,我得到了服务器 403 响应:
但是我打开了我的测试页面“forbidden-test”,我确实得到了我自定义的forbidden.php页面
这是我在 htaccess 中的内容,以下示例仅通过显示我的自定义 403 页面 RewriteRule ^forbidden-test$ - [F] 起作用:
Options All -Indexes
# prevent folder listing
IndexIgnore *
RewriteEngine on
RewriteCond %{HTTP_REFERER} \
... (there are many here)
mysite\.com|\
[L,NC]
RewriteRule .* - [F]
#spam blacklist end
RewriteCond %{HTTP_USER_AGENT} \
12soso|\
192\.comagent|\
1noonbot|\
1on1searchbot|\
3de\_search2|\
3d\_search|\
3g\ bot|\
... (there are many here)
zyte\
[NC]
RewriteRule .* - [F]
#bad bots end
#Forbidden Test
RewriteRule ^forbidden-test$ - [F]
#ERRORS
RewriteRule ^forbidden/?$ forbidden.php [L,QSA]
ErrorDocument 403 /forbidden
有什么想法吗? 谢谢
【问题讨论】:
-
尝试将
ErrorDocument 403 /forbidden放在 .htaccess 文件的顶部 -
@anubhava 相同的结果 :( 谢谢
-
RewriteCond %{HTTP_REFERER} \ ... (这里有很多) mysite\.com|\ [L,NC], L 可能会出错。
-
感谢@jacouh,为简单起见,我将它们全部删除,但它们都在工作,我什至只用一个 (mysite.com) 测试了代码并得到了相同的结果,感谢您的输入。
标签: .htaccess http-status-code-403 custom-error-pages