apache的301跳转,以及泛指向域名的接收

网站改版,域名改变,需要把老域名指向好链多, www.haolianduo.com,但是权重收录还不能丢,这时候就要使用到301重定向了。我这里说到的是使用apache虚拟主机VirtualHost的时候,如何配置301重定向:

#toooom.com redirect to haolianduo.com
<VirtualHost 192.168.1.12:80>
    ServerAdmin [email protected]
    ServerName toooom.com
    ServerAlias www.toooom.com
    RedirectMatch Permanent ^/(.*) http://www.haolianduo.com/$1
</VirtualHost>


这里就是指将 toooom.com/ www.toooom.com 重定向到 好链多 http://www.haolianduo.com/


顺便记录一下配置中的ServerAlias,使用ServerAlias可以达到配置更多域名指向同一个网站

一、用于设置虚拟主机接收多个域名
一个虚拟主机常常会接收多个域名解析,比如:一个虚拟主机要同时接收 haolianduo.com, toooom.com两个域名,或者是两个二级域名,如:www.haolianduo.com, www1.haolianduo.com,对于这种情况,可以在用ServerAlias轻松做到
<VirtualHost 192.168.1.12>
	ServerName haolianduo.com #默认域名;
	ServerAlias toooom.com www.haolianduo.com www1.haolianduo.com #不同域名用空格隔开;
	DocumentRoot "/haolianduo"
	<Directory "/haolianduo">
	Options Indexes FollowSymLinks
	AllowOverride all
</Directory>
</VirtualHost>



二、 用于接收泛域名解析
一个虚拟主机是可以接收泛域名解析的,也是通过SeverAlias选项设置,通过设置该选项不仅可以接收二级泛域名解析,也可以接收三级、四级泛域名解析,具体设置如下:
<VirtualHost 192.168.1.12:80>
	ServerName haolianduo.com #默认域名;
	ServerAlias *.haolianduo.com #用*表示泛域名,如果要接收三级泛域名解析,可以写成这样:*.my.haolianduo.com;
	DocumentRoot "/haolianduo"
	<Directory "/haolianduo">
	Options Indexes FollowSymLinks
	AllowOverride all
</Directory>
</VirtualHost>


保存后,重启apche即可生效。

猜你喜欢

转载自ziyu-1.iteye.com/blog/1748851