2014-01-31 44 views
2

是否有可能爲正常的域和子域創建VirtualDocumentRoot?VirtualDocumentRoot域和子域

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

用途:

/var/www/example.com/ 

而且

http://*.example.com 

用途

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

是我到目前爲止有: Pastebin - VirtualDocumentRoot Domains and Subdomains

正常的域名除了子域名外,其實它總是重定向到正常的域名。我用這個信息是從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 [email protected] 
    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> 

回答

0

您可以在服務器上指定的文件夾爲每個域和/或子域:) 請參閱http://httpd.apache.org/docs/current/vhosts/examples.html的樣本。

如果您遇到子域名或域名問題,請檢查您的DNS記錄,查看是否爲您的域啓用了子域名。否則,請在您的子域名或類似* .doamin.com的別名中添​​加'A'記錄。Basiccly這樣做會將子域名指向您的服務器IP地址。

檢查這篇文章的一個簡單的指南,DNS:https://support.google.com/a/answer/48090?hl=en

+0

隨着VirtualDocumentRoot我想阻止標準域整合的重複,又見我的貼分檔代碼。 我使用A記錄。 –

+0

您是否嘗試過調試您的主機文件? 使用'httpd -S'或'apache2ctl -S' 或者替代'APACHE_RUN_USER = www-data APACHE_RUN_GROUP = www-data/usr/sbin/apache2 -S' 根據您的服務器配置,您應該添加自己的路徑。 –

+0

發現此線程的調試信息:http://stackoverflow.com/questions/5474477/how-to-debug-an-apache-virtual-host-configuration –