【问题标题】:subdomain to sub folder mapping子域到子文件夹的映射
【发布时间】:2021-07-03 08:16:29
【问题描述】:

例如我的子域是 abc.example.com

我的文件夹是 /htdocs/abcfiles

我的要求是当我访问 url http://abc.example.com 时。 它将显示“abcfiles/”文件夹中的网页。

我的 .htaccess 文件

RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc.example.com$
RewriteCond %{REQUEST_URI} !^/abcfiles/
RewriteRule (.*) /abcfiles/$1 [L]
RewriteBase /abcfiles/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abcfiles/index.php [L]

它可以工作,但在某些链接中显示“/abcfiles/”。即 abc.example.com/abcfiles/...

【问题讨论】:

    标签: php apache .htaccess


    【解决方案1】:

    您可以在站点根目录 .htaccess 中拥有此代码:

    RewriteEngine On
    
    # if /abcfiles/ is in URL then remove it
    RewriteCond %{THE_REQUEST} \s/abcfiles/(\S*) [NC]
    RewriteRule ^ /%1 [L,NE,R=301]
    
    # if hostname starts with abc. then route the request to abcfiles/
    RewriteCond %{HTTP_HOST} ^abc\. [NC]
    RewriteCond %{REQUEST_URI} !^/abcfiles/ [NC]
    RewriteRule (.*) abcfiles/$1 [L]
    

    abcfiles/.htaccess中有此代码:

    RewriteEngine On
    
    RewriteRule ^index\.php$ - [L,NC]
    
    # route every request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    【讨论】:

    • 它工作正常。谢谢。但在页面源窗口中显示带有链接的“abcfiles/”
    • 那可能是旧的浏览器缓存。在新的浏览器中测试它
    猜你喜欢
    • 1970-01-01
    • 2015-02-24
    • 2012-07-16
    • 2012-06-11
    • 2015-08-06
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多