【问题标题】:How to disable direct linking with htaccess after subdomain redirection?如何在子域重定向后禁用与 htaccess 的直接链接?
【发布时间】:2017-03-13 18:09:57
【问题描述】:

我有一个重定向到特定目录地址的子域。如果直接访问,如何禁用该目录地址?

sub.domain.com 重定向到 domain.com/sub。当我直接访问domain.com/sub 时,它应该重定向到错误 404。

谢谢

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    当我直接访问 domain.com/sub 时,它应该重定向到错误 404。

    您可以将此规则用作sub/.htaccess 中的第一条规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^sub\. [NC]
    RewriteRule ^ - [L,R=404]
    

    【讨论】:

      【解决方案2】:

      在文档根目录的 htaccess 中,添加:

      RewriteEngine on
      
      RewriteCond %{HTTP_HOST} !^sub.domain.com$
      RewriteRule ^folder - [R=404,L]
      

      如果请求的主机不是 sub.domain.com,这会将所有以 /folder 开头的请求重定向到 404 页面。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-08-07
        • 2012-04-19
        • 2011-07-17
        • 2013-09-26
        • 2019-06-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多