仅允许来自特定引荐来源网址的用户(重定向其余用户)-HTACCESS [英] Only allow users from specific referrer (redirect the rest) - HTACCESS

查看:67
本文介绍了仅允许来自特定引荐来源网址的用户(重定向其余用户)-HTACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图阻止所有试图查看.php页面的人的访问,而这些访问都来自我的特定跟踪链接.

I've been trying to block access from everyone that is trying to see a .php page without coming from my specific tracking link.

我希望,如果它们不是来自我的链接,则将其重定向到另一个网站. 我尝试使用.htaccess方法,如下所示:

I want that if they're not coming from my link, they be redirected to another website. I tried using .htaccess method as following:

    RewriteEngine On
RewriteBase /

# allow these referers to passthrough
RewriteCond %{HTTP_REFERER} ^http://subdomain.domain.com
RewriteRule ^ - [L]

# redirect everything else
RewriteRule ^ http://anotherDomain.com/ [R,L]

这是因为 http://subdomain.domain.com 是一个重定向到website.php的跟踪网址.但似乎不起作用,尽管有任何引荐来源,甚至直接在工具栏中键入website.php的网址,也会将用户带到website.php.

this is because http://subdomain.domain.com is a tracking url that redirects to website.php but it seems that is not working, and despite any referrer, or even typing the url for website.php directly in toolbar is taking the user to website.php.

我要实现的是,只有subdomain.domain.com用户才能看到website.php

what I want to achieve is that only from subdomain.domain.com users can see website.php

提前谢谢.

推荐答案

您可以使用order deny,allow进行此操作,并将其放入您的.htaccess文件中:

You can do that using order deny,allow, put this into your .htaccess:

order deny,allow
deny from all
allow from subdomain.domain.com

这将拒绝所有人访问,除非他们通过subdomain.domain.com

This will deny everyone access unless they visit via subdomain.domain.com

然后重定向不来自subdomain.domain.com的用户,您可以使用:

Then to redirect the users who're not coming from subdomain.domain.com you can use:

RewriteCond %{HTTP_HOST} !^www\.subdomain.domain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/?(.*)         http://www.example.com/$1 [L,R,NE]

对于Apache 2.4:

For Apache 2.4:

由于使用的是2.4,因此可以使用IF指令:

You can use an IF directive since you're using 2.4:

<If "%{HTTP_HOST} != 'www.subdomain.domain.com'">
Redirect / http://www.example.com/
</If>

,并在order deny,allow周围添加以下内容:

and for the order deny,allow add the following around it:

<Limit GET>
</Limit>

这篇关于仅允许来自特定引荐来源网址的用户(重定向其余用户)-HTACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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