[root@www abc]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
DocumentRoot "/data/www"
ServerName www.qq.com
ServerAlias www.aqq.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
#users ren zheng
<Directory /data/www/abc> //用户认证
AllowOverride AuthConfig
AuthName "qqx"
# AuthUserFile /data/.htpasswd
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>
<IfModule mod_rewrite.c> //域名跳转301
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.qq.com$
RewriteRule ^/(.*)$ http://www.xx.com/$1 [R=301,L]
</IfModule>
</VirtualHost>
添加多个虚拟主机时,servername 要不同,才能访问
本文转自 linuxpp 51CTO博客,原文链接:http://blog.51cto.com/1439337369/1706678,如需转载请自行联系原作者