在实际生产环境中Apache服务器上web站点往往因为需要维护或者是弃用旧的域名时需要使用域名重定向,那么就可以利用Apache服务的rewrite规则快速的修改虚拟主机实现301重定向,如果还不了解http的状态码的可以看:http://jim123.blog.51cto.com/4763600/1836154

<VirtualHost *:80>
   DocumentRoot "/data/www/www.test1.com"
   ServerName  www.test1.com#实际的域名
   <Directory  /data/www/www.test1.com>
         AllowOverride all
         RewriteEngine on
         Order allow,deny
         Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
   ServerName  www.test2.com#需要跳转的域名
   RedirectMatch  permanent ^/(.*)  http://www.test1.com/$1#跳转www.test1.com
</VirtualHost>

重启Apache后,使用curl -I www.test2.com验证下,返回的http状态值是301就是成功