所在位置:首页 > 学习心得 > 301重定向和.htaceess文件设置
301重定向和.htaceess文件设置
  • 301重定向和.htaceess文件设置
    发布时间:2011-02-12 类别:PHP技术 来源:侠客工作室
    • 1
    • 2
    • 3
    • 4
    • 5
  • 301重定向和.htaceess文件设置

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

    www.54xiake.cn
    54xiake.cn/
    www.54xiake.cn/index.html
    54xiake.cn/index.php

    而这样导致:你站点主域名的pr值分散到其他几个URLs了。

    如果你用301重定向把其他三个URL转到
    www.54xiake.cn
    PR也就集中在主域名:www.54xiake.cn 了。

    301重定向具体办法:

    设置.htaccess文件(只适用于linux系统,并需要虚拟主机支持。)

    使访问54xiake.cn/的时候就会自动转到www.54xiake.cn
    在.htaccess文件里写上以下代码即可。

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

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

    附:.htaceess文件设置
    ##

    # if you want to use mod_rewrite, set this ‘On‘
    RewriteEngine On

    # the path to your site installation
    RewriteBase /

    # Maintenance Section - Uncomment the lines below according to your need
    # Write below your client IP address (e.g.: 127.0.0.1)
    # if you need to keep your web access during maintenance
    #RewriteCond %{REMOTE_ADDR}          !^127.0.0.1$
    # Choose your way of closing the access to PMF:
    # a. you can simply forbid access (HTTP 403 Error)
    #RewriteRule ^(.*)$                  underMaintenance.htm [F,L]
    # b. return the user an explanation
    #RewriteRule ^(.*)$                  underMaintenance.htm [L]

    # url canonicalization
    RewriteCond %{http_host} ^seowhy.com [NC]
    RewriteRule ^(.*)$ http://www.54xiake.cn/$1 [L,R=301]

    # show all categories
    RewriteCond %{REQUEST_URI}          showcat\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=show [L,QSA]

    # the search page
    RewriteCond %{REQUEST_URI}          search\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=search [L,QSA]

    # the add content page
    RewriteCond %{REQUEST_URI}          addcontent\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=add [L,QSA]

    # the ask question page
    RewriteCond %{REQUEST_URI}          ask\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=ask [L,QSA]

    # the open questions page
    RewriteCond %{REQUEST_URI}          open\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=open [L,QSA]

    # the help page
    RewriteCond %{REQUEST_URI}          help\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=help [L,QSA]

    # the contact page
    RewriteCond %{REQUEST_URI}          contact\.html$ [NC]
    RewriteRule ^(.*)$                  index.php?action=contact [L,QSA]

    # a page with a record
    RewriteCond %{REQUEST_URI}          ([0-9]+)_([0-9]+)_([a-z\-]+)\.html$ [NC]
    RewriteRule ^(.*)_(.*)_(.*)\.html$  index.php?action=artikel&cat=$1&id=$2&artlang=$3 [L,QSA]

    # a category page
    RewriteCond %{REQUEST_URI}              category([0-9]+)\.html$ [NC]
    RewriteRule ^category(.*)\.html$        index.php?action=show&cat=$1 [L,QSA]

    # a category page with page count
    RewriteCond %{REQUEST_URI}              category([0-9]+)_([0-9]+)\.html$ [NC]
    RewriteRule ^category(.*)_(.*)\.html$   index.php?action=show&cat=$1&seite=$2 [L,QSA]

    # start page
    RewriteRule index.html$ index.php [PT]

    # sitemap
    RewriteCond %{REQUEST_URI}              sitemap-([a-zA-Z0-9漩周遌*)_([a-z\-]+)\.html$ [NC]
    RewriteRule ^sitemap-(.*)_(.*)\.html$   index.php?action=sitemap&letter=$1&lang=$2 [L,QSA]

    # a solution id page
    RewriteCond %{REQUEST_URI}              solution_id_([0-9]+)\.html$ [NC]
    RewriteRule ^solution_id_(.*)\.html$    index.php?solution_id=$1 [L,QSA]

    # 404 page
    ErrorDocument 404 /404.html

  • ☆☆☆技术交流群:5684178☆☆☆
  • 上一篇:php中foreach()的两种用法详细说明
  • 下一篇:PHP构造函数和析构函数
侠客工作室主要承揽网站制作|企业建站|北京网站制作|北京网站建设|北京企业建站|专业仿站|SEO优化等业务
地址:北京市海定区清河水木天成 电话:13718388147 13718388147 传真:13718388147 访问统计:
投诉电话:13718388147 投诉QQ:点击这里给我发消息 客服信箱:1300105556@qq.com 邮编:102200 北京网站建设地图 北京网站建设RSS地图
版权所有 2009-2014侠客工作室【北京网站建设】 京ICP备11021494号-1