4-3.301重定向怎么进行URL标准化设

经常会碰到这样的情况,其他网站链接你的站点时,会用下面的链接:

www.httproot.com
httproot.com/
www.httproot.com/index.html
httproot.com/index.php

而这样导致:你站点主域名的pr值分散到其他几个URLs了。
如果你用301重定向把其他三个URL转到
www.httproot.com
PR也就集中在主域名:www.httproot.com了。

301重定向具体办法:
设置.htaccess文件(只适用于linux系统,并需要虚拟主机支持。)
使访问httproot.com/的时候就会自动转到www.httproot.com
.htaccess文件里写上以下代码即可。

RewriteEngine on
RewriteCond %{http_host} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.httproot.com/$1 [L,R=301]

注意:URL标准化的301重定向(以上代码)需要写在其他URL-rewrite代码之前。

HTTPROOT | 自学PHP | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 石头哥 |微信小程序 |木讯 |备案
Copyright © 1998 - 2016 HTTPROOT.COM. All Rights Reserved httproot.com 版权所有