我想要做的是将所有访问者转到example.com到www.example.com.it似乎是一个非常普遍的任务,但由于某种原因,它不适用于这个特定的网站。它总是指向默认的。 奇怪的是,如果我用另一个域名(yyyyy.com和www.yyyyy.com)replace这个域名,它可以正常工作。我检查了我的DNS,并且parsing到了正确的IP。
这里是我的虚拟主机configuration:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/example.com Servername www.example.com <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/html/example.com> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost > <VirtualHost *:80> ServerAdmin webmaster@localhost Servername example.com Redirect 301 / http://www.example.com </VirtualHost>
这是wget -S http://example.com的输出
HTTP request sent, awaiting response... HTTP/1.1 200 OK Date: Thu, 05 Jun 2014 07:11:50 GMT Server: Apache/2.2.22 (Ubuntu) Last-Modified: Tue, 06 May 2014 16:10:43 GMT ETag: "222c32-b1-4f8bd7d6326c0" Accept-Ranges: bytes Content-Length: 177 Vary: Accept-Encoding Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html
要获得ServerName VirtualHost工作,您需要启用NameVirtualHost 。 确保你的configuration中有这个行:
NameVirtualHost *:80