标签归档:no-www

apache .htaccess no-www to www

参考:http://www.askitexpert.com/question/redirect-nonwww-to-www-in-apache/10

有两种办法

1.在.htaccess的适当位置加入如下代码 yourdomain改成你的域名

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC]
RewriteRule ^(.*) http://www.yourdomain.com/$1 [L,R=301]

2.在 apache的配置文件中

RewriteEngine On
RewriteOptions Inherit
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.yourdomain.com/$1 [L,R]

继续阅读