现在我创build了两个文件一个用于example.com,另一个用于www.example.com,因为通配符* .example.com无法正确访问example.com我的问题是如何使example.comredirect到www.example.com使用Apache而不是像PHP一样的东西。 所以我可以有一个虚拟主机configuration每个域。
使用:
SeverName example.com ServerAlias www.example.com
在您的虚拟主机configuration…
那么你可以redirectnon-www到www类似的东西:
<IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteCond %{HTTP_HOST} (.+)$ [NC] RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L] </IfModule>