基于HTTP_REFERER是空的.htaccess重定向 [英] .htaccess Redirect based on HTTP_REFERER being empty

查看:835
本文介绍了基于HTTP_REFERER是空的.htaccess重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个WP博客安装,能够检测到任何人无处进来的(即不是从其他网站)重定向。我们的想法是陷阱一些插件pre-构造的URL到系统创建的意见/职位垃圾邮件机器人的。我想如果他们没有一个引用的网站,我可以弹出他们回到主页(www.domain.com/index.php或只是www.domain.com),这应该乱用机器人而不是与真实的人

I'm trying to set up a redirect on a WP blog installation that will detect anyone coming in from nowhere (i.e. not from another site). The idea is to trap some of the spambots that plug pre-constructed URLs into the system to create comments/posts. I figure if they don't have a referrer site, I can pop them back to the homepage (www.domain.com/index.php or just www.domain.com), which should mess with the bots but not with real people.

据我所知,介绍人可以伪造的,但希望它会停一帮愚,至少。

I understand that the referrers can be forged but hopefully it'll stop the stupids, at least.

我有关于的.htaccess重写规则(我为是一个小白道歉)很少的线索,但我无法找到一个这样做是在现有的答案或其他地方上网,尽管一些搜索。无论是没有人做了或者说我不措辞正确。

I have very little clue about .htaccess rewrite rules (I apologise for being a noob), but I couldn't find one that did this in existing answers or anywhere else online, despite several searches. Either no one's done it or I'm not phrasing correctly.

任何帮助AP preciated。 :)

Any help appreciated. :)

推荐答案

我会反对这项建议。通过这样做,你可能会惹恼和疏远潜在用户的一部分,例如:我的浏览器被设置为不报告引用者信息,其他人使用匿名网络。转储机器人,你可以通过匹配的报用户代理字符串(如看到的)>。

I'd advise against this. By doing it, you may annoy and alienate a portion of potential your users: for example my browser is set not to report referer information, others use anonymity networks. The dump bots you can catch by matching their reported user agent string (as seen here).

否则,它很简单:对在的RewriteCond的HTTP_REFERER环境变量匹配:

Otherwise it's simple: match against the HTTP_REFERER environmental variable in a RewriteCond:

RewriteCond %{HTTP_REFERER} ^$
RewriteRule .* http://example.com/

本的RewriteCond检查是否引用者是一个空字符串;在重写规则重定向一切 http://example.com/ 的根源。这是一个很难的重定向,这意味着服务器将发出R = 301永久移动头。如果你只是想悄悄成为另一种资源,通过指定一个相对URL,例如重写规则使用柔软的重定向。*的index.php 。但是,它可能是友善的人不报告引用信息重定向到一个网页说像你应该能够引用的报告,如果你想阅读此页。

The RewriteCond checks to see if the referer is an empty string; the RewriteRule redirects everything to http://example.com/ root. This is a hard redirect, meaning that the server will issue an R=301 moved permanently header. If you just want to sneakily serve another resource, use a soft redirect by specifying a relative URL, like RewriteRule .* index.php. However, it may be kinder for people not reporting referrer information to redirect them to a page saying something like "You should enable referrer reporting if you want to read this page".

有关这样的事情更多示例,请参见手册。有有非常相似的prevent盗链的方法。

For more examples on such things, see the manual. There's a very similar prevent-hotlinking method there.

这篇关于基于HTTP_REFERER是空的.htaccess重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆