.htaccess 使用htaccess允许url中的动态子域

.htaccess 使用htaccess允许url中的动态子域,.htaccess,subdomain,.htaccess,Subdomain,我已经为我的网站创建了一个虚拟主机www.maindomain.com。我希望允许在url中使用htaccess的动态子域,即test.maindomain.com、abc.maindomain.com等。我的站点文件夹结构是www/test/index.php 以下是我当前的htaccess代码: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] Rewrit

我已经为我的网站创建了一个虚拟主机www.maindomain.com。我希望允许在url中使用htaccess的动态子域,即test.maindomain.com、abc.maindomain.com等。我的站点文件夹结构是www/test/index.php

以下是我当前的htaccess代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z]+)\.maindomain\.com$ [NC]
RewriteRule .? index.php?url=%1&path=%{REQUEST_URI} [L,QSA]    
</IfModule>

重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{HTTP_HOST}^www\.maindomain\.com$[NC]
重写cond%{HTTP\u HOST}^([a-z]+)\.maindomain\.com$[NC]
重写规则。?php?url=%1&path=%{REQUEST_URI}[L,QSA]
我找不到服务器,无法连接错误消息

有人能给我一个解决这个问题的好办法吗


提前谢谢

如果您的服务器处于联机状态:

您需要在VirtualHost中加上一个通配符
serverAlias

<VirtualHost *:80>
    ServerAdmin admin@example.local
    DocumentRoot "/my_server/htdocs"
    ServerName example.local
    ServerAlias *.example.local
    # [...]
</VirtualHost>

服务器管理员admin@example.local
DocumentRoot“/我的服务器/htdocs”
ServerName example.local
ServerAlias*.example.local
# [...]

最后,您将能够在
.htaccess
文件中捕获这些子域。

这些子域需要先注册