修改.htaccess文件实现301重定向

#ErrorDocument 404 /index.php?m=error
<Files *.tpl>
Order Allow,Deny   
Deny from all
</Files>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.wego.com.cn$ [NC]
RewriteRule ^(.*)$ http://www.wego.com.cn/$1 [L,R=301]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^index.html$     /index.php [L]
RewriteRule ^([a-zA-Z0-9_]+)\.html$    /index.php?m=$1 [L]
RewriteRule ^weather-([0-9]+)-([0-9]+)\.html$   /index.php\?m=weather&cityid=$1&xid=$2 [L]

RewriteRule ^news-c([0-9]+)-([0-9]+)\.html$   /index.php\?m=news&class_id=$1&page=$2 [L]
RewriteRule ^news-c([0-9]+)\.html$    /index.php\?m=news&class_id=$1 [L]
RewriteRule ^news-([0-9]+)\.html$    /index.php\?m=news&page=$1 [L]
RewriteRule ^newsinfo-([0-9]+)\.html$    /index.php\?m=newsinfo&aid=$1 [L]

RewriteRule ^liansuo-([0-9]+)-([0-9]+)\.html$   /index.php\?m=liansuohotel&cityid=$1&chain_id=$2 [L]
RewriteRule ^liansuo-([a-zA-Z_]+)-([0-9]+)\.html$  /index.php\?m=liansuohotel&$1=$2 [L]

RewriteRule ^city-([0-9]+)\.html$    /index.php\?m=city&cityid=$1 [L]

RewriteRule ^hotel-([0-9]+)-([0-9]+)\.html$   /index.php\?m=hotelinfo&cityid=$1&hotel_id=$2 [L]
RewriteRule ^hotel-([0-9]+)\.html$    /index.php\?m=hotelinfo&hotel_id=$1 [L]
RewriteRule ^(hotelmap|hotelcomment|hotelnearby|hotelpicture|hotelquestion|hotellable)-([0-9]+)\.html$ /index.php\?m=$1&hotel_id=$2 [L]

RewriteRule ^(comment|question|weather|searchlist)-([0-9]+)-([0-9]+)\.html$  /index.php\?m=$1&cityid=$2&page=$3 [L]
RewriteRule ^hotellist-([0-9]+)\.html?([\w%]*)$   /index.php\?m=hotellist&cityid=$1&$2 [QSA,L]
RewriteRule ^(comment|question|weather|map|hotellist|searchlist|member|city)-([0-9]+)\.html$  /index.php\?m=$1&cityid=$2 [L]

RewriteRule ^(comment|question)-p([0-9]+)-([0-9]+)\.html$  /index.php\?m=$1&pid=$2&cityid=$3 [L]

RewriteRule ^lable-cityid([0-9]+)-([0-9]+)-([0-9]+)\.html$ /index.php\?m=lable&cityid=$1&classid=$2&page=$3 [L]
RewriteRule ^lable-(pid|cityid)([0-9]+)-([0-9]*)\.html$         /index.php\?m=lable&$1=$2&classid=$3 [L]
RewriteRule ^lable-([0-9]+)-([0-9]+)\.html$                 /index.php\?m=lable&pid=$1&cityid=$2 [L]
RewriteRule ^lable-([0-9]+)\.html$    /index.php\?m=lable&classid=$1 [L]
RewriteRule ^teamsinfo-([0-9]+)\.html$    /index.php\?m=teamsinfo&id=$1 [L]
RewriteRule ^teams-city-([0-9]+)\.html$           /index.php\?m=teams&cityid=$1 [L]

RewriteRule ^pic/(zn)/(.*+)$   /pic.php\?m=$1&p=$2 [L]
RewriteRule ^pic/(.*+)$   /pic.php\?p=$1 [L]

下面再转一篇不错的文章给大家看下,我就是按照下面这个来修改的。

出于SEO、PR值传递、网址转换的目的,在网站初建和网站迁移时我们都需要使用301重定向,通常包括域名对域名,目录对目录和一个独立网址对另一个独立网址的重定向。在bluehost虚拟主机上作301重定向,最常用的方法有2种:
1.直接编辑.htaccess。
2.用cPanel设定。
实质二者都是修改文件.htaccess,只是前者手工编辑,后者是由cPanel完成。用cPanel操作相当简单,登陆你的 cPanel(bluehost虚拟主机可以选简体中文)–>Domain–>Redirects,选择相应的选项即可完成设置,这里暂不讨论。下面讲一下直接编辑.htaccess的方法。
注意:在设置301重定向之前务必备份相应目录下的.htaccess文件。
1.重定向domain.com到www.domain.com
这种重定向旨在使域名唯一,是网站SEO必须要做的,后面重定向www.domain.com到domain.com也是出于同样的原因,只是形式不同。
打开.htaccess文件,加入以下规则。(下面的规则是针对主域名的,子域名要修改)

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

2.重定向www.domain.com到domain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

3.重定向olddomain.com到www.newdomain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} !olddomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]

4.重定向olddomain.com to newdomain.com

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !olddomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

5.重定向domain.com/file/file.php 到 otherdomain.com/otherfile/other.php

RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [R=301,L]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值