简体   繁体   English

将人们重定向到网站

[英]Redirect people to website

I'm trying to figure out how I can redirect all traffic on a certain domain to my other website, based on the referrer. 我试图弄清楚如何基于引荐来源网址将某个域上的所有流量重定向到我的其他网站。

For example, we only want people with no referrer, or linked to from our other website, to be able to access the site. 例如,我们只希望没有引荐来源或从我们其他网站链接的人能够访问该网站。

I was thinking of a script that would redirect everyone to a website of my choice, if their referrer didn't match the site I specify (but still allowed no referrer traffic). 我在考虑一个脚本,如果他们的引荐来源与我指定的网站不匹配(但仍不允许引荐访问量),该脚本会将所有人重定向到我选择的网站。

Any help is appreciated! 任何帮助表示赞赏!

The following PHP code should do it (but remember, this cannot be used as a security measure, since the Referer header is provided by the client): 下面的PHP代码应该做到这一点(但是请记住,由于Referer标头是由客户端提供的,因此不能用作安全措施):

if (isset($_SERVER['HTTP_REFERER']) &&
    $_SERVER['HTTP_REFERER'] &&
    stripos($_SERVER['HTTP_REFERER'], "example.org") === false) {
    header("Location: http://example.com/", true, 302);
    exit();
}

Here we check that the client provided the Referer header, next that it is non-empty, and finally that it lacks the proper domain name (here "example.org"). 在这里,我们检查客户端是否提供了Referer标头,其次是非空的,最后是缺少正确的域名(此处为“ example.org”)。 If so, we redirect the client to another URL (here "http://example.com/") and exit. 如果是这样,我们会将客户端重定向到另一个URL(此处为“ http://example.com/”)并退出。

您可以只检查HTTP引用(故意拼写错误)标头:

if (!stristr($_SERVER['HTTP_REFERER'], "somesiteyouspecify") && !$_SERVER['HTTP_REFERER'] == '') ... redirect

you should configure that as RewriteRules in the webserver like Apache or nginx. 您应该在Web服务器(例如Apache或nginx)中将其配置为RewriteRules。 Examples can be found easily in the documentation ... (I would give one, if I knew the used webserver software ...) 示例可以在文档中轻松找到...(如果我知道所使用的网络服务器软件,我可以举一个例子...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM