只允许某些IP访问网站,除了特定的URL(对任何IP开放)

时间:2017-04-10 15:25:15

标签: apache .htaccess

我知道.htaccess中的以下内容只允许某个IP访问网站:

Order deny,allow
Deny from all
Allow from xxx.xxx.xxx.xxx

但我想扩展这个以允许任何IP访问特定的URL(即www.mywebsite.com/any)。

所以我的IP可以访问整个网站,但我朋友的IP只能访问特定的URL。它不需要转发到。

我该怎么做?

3 个答案:

答案 0 :(得分:1)

对于处于类似情况的任何人,这里是我使用的代码:

<Files "">
Order allow,deny
allow from 192.168.0.1
</Files>

<Files "any">
Order allow,deny
allow from all
</Files>

答案 1 :(得分:0)

您可以使用mod-rewrite而不是Allow / deny指令:

SELECT TOP(1) x.Id, x.OtherColumnNames...
FROM Transaction as x
LEFT JOIN Enterprise AS e1 on x.EnterpriseId = e1.Id
LEFT JOIN Enterprise AS e2 on x.EnterpriseId = e2.Id
LEFT JOIN Manager AS m1 on e2.ManagerId = m1.Id
LEFT JOIN Enterprise AS e3 on x.EnterpriseId = e3.Id
LEFT JOIN Address AS a1 on e3.AddressId= a1.Id
LEFT JOIN Enterprise AS e4 on x.EnterpriseId = e4.Id
LEFT JOIN Example AS e1 on e4.ExampleId= e1.Id
...

这会将除 yourIP 之外的所有其他IP地址重定向到 / any

答案 2 :(得分:-1)

“位置/”是您的网址(mysite.com)的根,只有特定的IP(例如192.168.0.1o)才能访问,而位置/全部是每个人都访问的网站的一部分(mysite.com) /全部)。

<Location />
Order Allow,deny
Allow from myIP #Allow from 192.168.0.10
</Location>

<Location /all> 
Order Allow,deny
Allow from all
</Location>

容易愚蠢如果您阅读doc's

相关问题