Apache2不能在虚拟主机中将非WWW重定向到WWW



我在tomcat(6)前面有一个apache(2.4.6)服务器。我希望所有请求www.domain.com永久重定向到domain.com。我当前的配置文件是:

<VirtualHost *:80>
ServerName www.domain.ma
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.ma
RewriteRule ^(.*)$ http://www.domain.ma/$1 [R=permanent,L]
DocumentRoot /var/www/domain.ma/htdocs
ProxyRequests Off
ProxyPreserveHost On
ProxyPassReverseCookiePath /portal /
ProxyPass /portal/index.htm http://127.0.0.1:8080/portal/index.htm
ProxyPass /images !
ExpiresByType image/* A2592000
</VirtualHost>

当我请求http://domain.ma/时,apache没有重定向到http://www.domain.ma/,有人能告诉我我的配置中有什么问题吗?

试试这个:

ServerName domain.ma
ServerAlias www.domain.ma 
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.domain.ma [NC]
RewriteRule (.*) http://www.domain.ma/$1 [R=301,L]

最新更新