在Apache中重写vHost的URL。 [AllowOverride&已检查Mod_rewrite]

时间:2015-07-31 14:00:57

标签: .htaccess mod-rewrite apache2 no-www

我在使用www将规范网址重写为我的域中的非www时遇到问题。 如果我尝试www.example.com,我总是得到#404。 以下是有关apache2配置的所有信息。

这就是我所检查的内容:

/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
        ServerAdmin info@example.com
        ServerName example.com
        DocumentRoot /var/www/example.com
        <Directory /var/www/example.com>
                AllowOverride All
	        <IfModule mod_rewrite.c>
        	        Options +FollowSymLinks
			RewriteEngine On
			RewriteCond %{HTTP_HOST} ^www.example.com [NC]
			RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
        	</IfModule>
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
	
</VirtualHost>

/etc/apache2/apache2.conf

.
.
.
<Directory />
	Options FollowSymLinks
	AllowOverride All
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
</Directory>
.
.
.

和最后一个信息 phpinfo() enter image description here

有什么想法吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

<强> [解决]

我刚刚在虚拟主机定义中添加了别名子句,并在DNS区域中创建了CNAME记录 www.example.com

ServerName example.com
ServerAlias www.example.com