VirtualDocumentRoot域和子域

是否有可能为正常的域名和子域名VirtualDocumentRoot?

http://www.example.com/ or http://example.com 

用途:

 /var/www/example.com/ 

 http://*.example.com 

用途

 /var/www/example.com/subdomains/* 

我到目前为止: Pastebin – VirtualDocumentRoot域名和子域名

正常的域名除了子域名之外,显然总是被redirect到正常的域名。 我使用的信息来自Stackoverflow – Apache-multiple-virtualdocumentroot

 # get the server name from the Host: header UseCanonicalName Off # this log format can be split per-virtual-host based on the first field LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon CustomLog logs/access_log vcommon <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName domain.com ServerAlias www.domain.com domain.com VirtualDocumentRoot /var/www/%-2.0.%-1/web # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel debug ErrorLog /var/log/apache2/vhosts-error.log CustomLog /var/log/apache2/vhosts-access.log combined ServerSignature On </VirtualHost> <VirtualHost *:80> ServerName domain.com ServerAlias *.domain.com VirtualDocumentRoot /var/www/%-2.0.%-1/subdomains/%-3 </VirtualHost> 

更新v2 [为我工作,只是忽略子域到现在..]

 <VirtualHost *:80> ServerName example.com ServerAlias www.example.com example.com Options Indexes FollowSymLinks VirtualDocumentRoot /var/www/%-2_%-1/web/ <Directory /> AllowOverride none </Directory> <Directory "/var/www/*/web/"> RewriteEngine on RewriteBase / # If a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward it to index.php RewriteRule . index.php [L] <Files sitemap.xml> RewriteEngine Off </Files> </Directory> LogLevel debug ErrorLog /var/log/apache2/vhosts-error.log CustomLog /var/log/apache2/vhosts-access.log combined </VirtualHost> 

您可以在服务器上为每个域和/或子域指定一个文件夹:)有关示例,请参见http://httpd.apache.org/docs/current/vhosts/examples.html

如果您遇到子域名或域名问题,请检查您的DNS记录,查看是否为您的域名启用了子域名。 否则,添加一个“A”记录与您的子域名或别名,如* .doamin.com Basiccly这是做什么,是指向子域到您的服务器的IP地址。

查阅这篇文章以获取DNS简易指南: https : //support.google.com/a/answer/48090?hl = zh_CN