Apache下访问不带www域名自动转到带www域名

18. January 2017 笔记 0

打开Apache22\conf\extra\httpd-vhosts.conf

修改VirtualHost如下

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot “/Apache22/htdocs”
ServerName lezhi.ren
ErrorLog “logs/error.log”
CustomLog “logs/access.log” common
<IfModule mod_rewrite.c>
rewriteEngine on //新加从此
rewriteCond %{http_host} ^lezhi.ren [NC] //修改成自己的域名
rewriteRule ^(.*)$ http://www.lezhi.ren$1 [R=301,L] //修改成自己的域名
</IfModule>
</VirtualHost>