子域到子文件夹的映射

subdomain to sub folder mapping

例如我的子域是 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/ [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/...

您可以在站点根目录 .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/ [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]