A-A+

Apache的各种重定向的实现

2016年01月13日 LINUX, 服务 暂无评论 阅读 1,670 次
1.访问网站某目录301重定向另外一个域名
<VirtualHost *:80>
ServerName www.iknowing.com
ServerAlias iknowing.com
DocumentRoot "f:/Apache2.2/htdocs/aa"
#将目录shsx下内容301重定向www.shanghaishuxie.cn
Redirect permanent /shsx  http://www.shanghaishuxie.cn/
</VirtualHost>
上面例子就是:
将访问www.iknowing.com/shsx 内容301重定向到www.shanghaishuxie.cn
2.访问某个域名重定向到另外一个域名的某个目录
<VirtualHost *:80>
ServerName lj.abc.cn
#DocumentRoot "C:/Apache2.2/htdocs/htdocs2/aa"
RedirectMatch 301 ^(.*) http://www.cde/lj/
</VirtualHost>
将lj.iknowing.cn 所有请求都重定向到  http://www.cde.cn/lj/
3.访问某个域名让浏览器自动跳转到该域名下的某个目录,不显示首页
比如 访问 www.abc.cn  直接定位到 www.abc.cn/lll
<VirtualHost *:80>
ServerName www.abc.cn
RedirectMatch ^/$ http://www.abc.cn/lll
</VirtualHost>
4.将域名A下的页面全部301重定向到域名B去,当网站要换域名的时候用到。
<VirtualHost *:80>
ServerName zazhi.sitebao.net
Redirect permanent / http://zazhi.wingsmedia.com.cn/
RedirectMatch (.*)\.html$ http://zazhi.wingsmedia.com.cn/
</VirtualHost>
3 、4行还可以这样
RewriteEngine ON
RewriteRule ^(.*)$ http://zazhi.wingsmedia.com.cn/$1 [R=301,L]
5.访问首页index.shtml跳转到域名根下。一般用于SEO优化,防止首页权重分散。
<VirtualHost *:80>
rewriteEngine on
rewriteRule /index.shtml http://www.sitebao.com/ [R=permanent,L]
6.输入域名自动跳转到该网站下的某页面,常用于某个重要的产品或事件页面宣传,大公司的网站进经常这样做。
<VirtualHost *:80>
ServerName farm.oasiseco.org
ServerAlias farm.oasiseco.org
</VirtualHost>
输入farm.oasiseco.org 就跳转到 http://farm.oasiseco.org/104.shtml ,不显示再首页,直接显示104.shtml页面内容。
7.访问域名下某个页面跳转到同域名下另外的一个页面
在虚拟主机中增加配置如下
Redirect permanent /main.html http://www.ipudong.net/index.shtml
 

给我留言