【问题标题】:Point domain to subdomain folder with same url将域指向具有相同 url 的子域文件夹
【发布时间】:2017-05-17 00:06:03
【问题描述】:

我有一个域名

http://www.example.biz/

我开发了一个站点并将代码放在该域的子文件夹中,例如,该站点位于

http://www.example.biz/site

现在,我想将我的主域指向这个文件夹,这样当用户访问 example.biz 时,他实际上会看到 example.biz/site,为此,我在 .htaccess 中添加了以下行

RedirectMatch ^/$ /site/

效果很好,但是用户看到的网址是

http://www.example.biz/site

我不希望这样,我希望用户只看到 http://www.example.biz 作为 URL,但这个域应该不可见地指向子文件夹。我该怎么做?

【问题讨论】:

    标签: .htaccess redirect subdomain


    【解决方案1】:

    使用 mod_rewrite 您可以使用以下规则,现在当您访问http://www.example.biz 时,它将显示来自site/ 的索引文件。

    RewriteEngine On
    RewriteRule ^$ /site/ [L]
    

    或者,如果您想显示每个文件,请尝试以下方式,

    RewriteEngine On
    RewriteRule ^(/|.+)$ site/$1 [L]
    

    【讨论】:

      【解决方案2】:

      我找到了一个更简单的解决方案,

      RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
      RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
      RewriteCond %{HTTP_HOST} ^(www\.)?example\.biz$
      RewriteRule !^site/ /site%{REQUEST_URI}  [L]
      

      【讨论】:

        猜你喜欢
        • 2019-02-05
        • 2013-11-22
        • 1970-01-01
        • 2014-06-19
        • 2016-12-19
        • 2023-03-16
        • 2011-02-12
        • 2021-06-14
        • 1970-01-01
        相关资源
        最近更新 更多