大网数据广告活动
网站运营与故障问答

Should I be returning a 301 or 403 to a bad referrer in my .htaccess?

· 52CE 我爱测

Getting several amounts of bad requests from a particular URL such as site.foo and I would like to redirect all these requests to a dedicated page. The .htaccess code I've researched and implementing is: RewriteCond %{HTTP_REFERE…

问题原文

原帖链接 · DᴀʀᴛʜVᴀᴅᴇʀ · CC BY-SA 3.0

Getting several amounts of bad requests from a particular URL such as site.foo and I would like to redirect all these requests to a dedicated page. The .htaccess code I've researched and implementing is:

RewriteCond %{HTTP_REFERER} http://site.foobar 
RewriteRule ^ https://bar.com/notallowed.html? [R=301,L]

However, researching HTTP Status codes I'm still unsure with the 301:

301 Moved Permanently
This and all future requests should be directed to the given URI. 

or the 403:

403 Forbidden
The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account of some sort.

So which is the proper usage case and am I using the proper rewrite rule? Is there a proper HTTP status code to use to stop bad referrers?

In my research I ran across:

In case the next person that runs across this is curious.

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 3.0

I would use the "403 Forbidden" status. You just need to change your rewrite rule

RewriteCond %{HTTP_REFERER} http://site.foobar 
RewriteRule ^ - [F]

Reference: https://httpd.apache.org/docs/trunk/rewrite/flags.html#flag_f

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。