子域始终redirect到主域 – Apache2 VirtualHosts&Debain

我想使用apache2 VirtualHosts来build立一个主站点和一个用于开发的子域。 这是我的site.conf虚拟主机文件的样子:

<VirtualHost *:80> ServerName dev.example.com DocumentRoot /var/www/site/subdomain <Directory /var/www/site/subdomain > Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel debug CustomLog ${APACHE_LOG_DIR}/sub.log combined </VirtualHost> <VirtualHost *:80> ServerName www.example.com ServerAlias example.com DocumentRoot /var/www/site/main <Directory /var/www/site/main > Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

问题是,我每次访问dev.example.com,我只是得到example.com。

我尝试了所有其他的解决scheme,我可以find(使用文字IPs,重新sorting的东西,使用端口,而不是命名主机)…我现在完全卡住了。 任何人有任何想法?

编辑:这是我的虚拟主机转储(相关部分):

  port 80 namevhost dev.example.com (/etc/apache2/sites-enabled/example.conf:1) port 80 namevhost www.example.com (/etc/apache2/sites-enabled/example.conf:44) 

另外,如果我删除主域名站点,则根本不会检测到子域名站点。

确保你启用你的网站

 a2ensite dev.mysite.com 

一旦你这样做,configuration文件的符号链接被放置在启用网站的目录中,这应该允许访问网站,假设没有其他问题存在。

这个问题提供了一些细节。

WordPress的是问题

或者说,我不知道我必须configurationWordPress的网站的url是子域,否则它只会redirect到给定的域…

所以解决scheme:打开wp_options表并编辑site_url包含子域。