使用基于引用的 htaccess 重定向 [英] Redirect using htaccess based on referrer

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

问题描述

我们只希望来自特定网站的用户使用我们的服务.有没有办法通过 htaccess 将所有不是来自特定引荐来源的流量重定向到我们选择的网站?

We only want users from a specific website to use our services. Is there a way to redirect all traffic that does not come from a specific referrer, to a website of our choosing, via htaccess?

此外,这仅适用于第一页.因此,如果他们访问我们的网站,他们将浏览一个新页面,而他们新页面的引荐来源显然是他们已经在的网站.

Also, this is for the first page only. So if they get to our site, they're going to browse a new page, and their referrer for the new page would apparently be the site they are already on.

谢谢!

推荐答案

尝试将其添加到文档根目录的 htaccess 文件中:

Try adding this in the htaccess file in your document root:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteRule ^/?first-page.html$ http://the-website-of-your-choosing.com/ [L,R]

您也可以这样做,以便将您自己的域添加到引用检查中:

You could also make it so you add your own domain to the referer check:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://your-domain.com [NC]
RewriteRule ^ http://the-website-of-your-choosing.com/ [L,R]

然后您可以将所有页面都包含在检查中.

Then you can include all of your pages in the check.

请注意,引用者很容易伪造,并且在您的任何子目录中使用 mod_rewrite 的任何 htaccess 文件都将取代这些规则(除非这些 htaccess 文件具有 RewriteOptions inheret 选项集)

Note that referers can be easily forged and any htaccess file using mod_rewrite in any of your subdirectories will supercede these rules (unless those htaccess files have the RewriteOptions inheret option set)

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

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