apache .htaccess no-www to www

有两种办法

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]

你可能感兴趣的:(apache .htaccess no-www to www)