linux 下的apache重定向

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优化,防止首页权重分散。


比如访问 www.sitebao.com/index.shtml 跳转到 www.sitebao.com
<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
RedirectMatch ^/$ http://farm.oasiseco.org/104.shtml
</VirtualHost>
输入farm.oasiseco.org 就跳转到 http://farm.oasiseco.org/104.shtml ,不显示再首页,直接显示104.shtml页面内容。
7.访问域名下某个页面跳转到同域名下另外的一个页面


如访问www.ipudong.net/main.html 跳转到http://www.ipudong.net/index.shtml
在虚拟主机中增加配置如下
Redirect permanent /main.html http://www.ipudong.net/index.shtml
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值