简体   繁体   English

使用基于引用者的htaccess重定向

[英]Redirect using htaccess based on referrer

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? 有没有办法通过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. 因此,如果他们访问我们的网站,他们将要浏览新页面,他们对新页面的推荐人显然是他们已经在的网站。

Thank you! 谢谢!

Try adding this in the htaccess file in your document root: 尝试在文档根目录中的htaccess文件中添加:

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. 然后,您可以在支票中包含所有页面。

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) 请注意,引用可以很容易伪造,任何子目录中使用mod_rewrite的任何htaccess文件都将取代这些规则(除非那些htaccess文件具有RewriteOptions inheret选项集)

Didn't work for me, I've made this small change to redirect traffic from google: 没有为我工作,我做了这个小改动来重定向来自谷歌的流量:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)\.google\.(.*) [NC]
RewriteRule ^(.*)$ https://www.my-site.it/$1 [L,R]

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

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