【问题标题】:Restrict access to web directory but allow sub-domain限制对 Web 目录的访问,但允许子域
【发布时间】:2011-04-17 13:41:37
【问题描述】:

我试图拒绝直接访问的人访问子域目录,而不是让他们直接浏览子域。例如,我希望人们能够访问 http://test.example.com 而不是 http://example.com/test。如果他们确实显示 403 Forbidden 错误。这可以通过 htaccess 实现吗?谷歌搜索但看不到有人这样做。主要目的是禁止他们直接访问内容。尝试以下方法均未成功。

<Directory /test>
  Order Deny,Allow
  Deny from all
  Allow from .example.com
</Directory>

【问题讨论】:

    标签: php apache .htaccess


    【解决方案1】:

    您可以进行从example.com/test/test.example.com 的永久重定向。这将确保每个人都以test.example.com 访问您的网站。这将更适合您的用户。

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^example.com [nc]
    RewriteRule ^test/(.*)$ http://test.example.com/$1 [r=301,nc] 
    

    如果你真的想显示 403 Forbidden,你可以这样做

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^example.com [nc]
    RewriteRule ^test/(.*)$ / [r=403,nc] 
    

    【讨论】:

    • 我感觉这也会将所有其他子域请求重定向到 test.example.com
    猜你喜欢
    • 2014-02-15
    • 2012-09-18
    • 2014-01-20
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    相关资源
    最近更新 更多