首页 > 开发 > Apache > 正文

.htaccess 301重定向详细教程

2020-10-12 18:50:03
字体:
来源:转载
供稿:网友

.htaccess这个模块是apache的一个算是叫扩展示模板吧,要能让它可以运行必须在RewriteEngine:让下面的rewrite功能打开或关闭。on是打开;off是关闭,可以的。

重定向老域名.com到www.新域名.com

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

重定向老域名.com to 新域名.com

  1. RewriteEngine On 
  2. RewriteBase / 
  3. RewriteCond %{HTTP_HOST} !老域名.com$ [NC] 
  4. RewriteRule ^(.*)$ http://新域名.com/$1 [L,R=301] 

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

  1. RewriteCond %{HTTP_HOST} ^www.domain.com$ 
  2. RewriteRule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [R=301,L] 
  3. RewriteBase /news 
  4. RewriteCond %{HTTP_HOST} ^Cuoxin.com [NC] 
  5. RewriteRule com(.*)$ http://www.Cuoxin.com$1 [L,R=301] 
#不加斜杠请求的地址是/wwwroot/Cuoxin.com/news/
 
  1. RewriteCond %{HTTP_HOST} ^Cuoxin.com [NC] 
  2. RewriteRule (.*)$ http://www.Cuoxin.com/news/$1 [L,R=301] 
  3. RewriteCond %{HTTP_HOST} ^124.173.133.154 [NC] 
  4. RewriteRule com(.*)$ http://www.Cuoxin.com$1 [L,R=301] 
  5. RewriteCond %{HTTP_HOST} ^124.173.133.154 [NC] 
  6. RewriteRule (.*)$ http://www.Cuoxin.com/news/$1 [L,R=301] 

# 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 / RewriteBase /

# Rewrite 系统规则请勿修改
 
  1. RewriteCond %{HTTP_HOST} !^www.Cuoxin.com$ [NC] 
  2. RewriteRule ^(.*)$ http://www.Cuoxin.com/$1 [L,R=301] 
  3. RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1 
  4. RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2 
  5. RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2 
  6. RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2 
  7. RewriteRule ^tag-(.+).html$ tag.php?name=$1 
[NC]:no case的缩写。意思是忽略大小写,a-z和A-Z是没有差别的。 
[NC,OR]:OR=AND。意思是此句要紧接着下一句语法。 
[R=301,L]:R=301:redirect的缩写。意思是用301永久转向(当网址在上述名单内,就自动转向至你指定的网址);L:Last的缩写,意思是最后一句了。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表