【问题标题】:Restrict access to few pages when Subdomain is used to access website使用子域访问网站时限制访问少数页面
【发布时间】:2014-08-10 21:34:45
【问题描述】:

我有一个网站,也可以通过子域访问。例如

www.example.com, abc.example.com and xyz.example.com

所有三个域都指向同一个网站。该网站对所有 3 个域的行为都不同。现在我的问题是我想限制对“关于我们”页面和“我们做什么”页面的访问,当它们通过子域访问时。我知道我可以从 PHP 进行重定向,但我想在请求转到 PHP 之前进行限制,比如在 htaccess 或 vhost 文件本身中。所以

www.example.com/aboutus - Must work BUT

abc.example.com/aboutus and xyz.example.com/aboutus - must not work

我在网上搜索了很多,但找不到解决方案。

请帮忙

提前致谢

【问题讨论】:

    标签: php apache .htaccess vhosts


    【解决方案1】:

    如果你有 mod_rewrite 你可以这样做:

    RewriteEngine on
    RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
    RewriteRule /aboutus http://www.example.com/errorpage [R,L]         
    

    如果调用 url /aboutus,它会查找任何不是 www.example.com 的主机。如需更多信息,请参阅docu

    【讨论】:

    • 非常感谢科尔伯顿
    猜你喜欢
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多