Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[已解决] [New.DST 技术/教程] 利用.htaccess的301跳转网址

[复制链接]
New.DST 发表于 2010-7-16 22:07:26 | 显示全部楼层 |阅读模式
首先
我们可以直接复制以下内容,便可达到伪静态的效果:
  1. # 将 RewriteEngine 模式打开
  2. RewriteEngine on

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

  5. # Rewrite 系统规则请勿修改
  6. RewriteCond %{QUERY_STRING} ^(.*)$
  7. RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
  8. RewriteCond %{QUERY_STRING} ^(.*)$
  9. RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
  10. RewriteCond %{QUERY_STRING} ^(.*)$
  11. RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
  12. RewriteCond %{QUERY_STRING} ^(.*)$
  13. RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
  14. RewriteCond %{QUERY_STRING} ^(.*)$
  15. RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
  16. RewriteCond %{QUERY_STRING} ^(.*)$
  17. RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
  18. RewriteCond %{QUERY_STRING} ^(.*)$
  19. RewriteRule ^([a-z]+)-(.+)\.html$ $1.php?rewrite=$2&%1
复制代码
下面我们来分析利用.htaccess的301跳转网址效果.
查找:
  1. RewriteEngine on
复制代码
在下方加入:
  1. RewriteCond %{http_host} ^17dst.com [NC]
  2. RewriteRule ^(.*)$ [url]http://www.17dst.com/[/url]$1 [L,R=301]
复制代码
RewriteCond %{http_host} ^17dst.com [NC]
表示:当请求地址不等于原网址(用代替)时跳转到新的网址(用代替)

RewriteRule ^(.*)$ http://www.17dst.com/$1 [L,R=301]
表示:永久重定向到新地址

简单的说:
17dst.com表示为被跳转的地址
http://www.17dst.com 表示跳转的地址

举例:
输入:17dst.com 将自动跳转至 http://www.17dst.com
输入:17dst.com/forum-43-1.html 将自动跳转至 http://www.17dst.com/forum-43-1.html
输入:17dst.com/gongju/gongju_01.html 将自动跳转至 http://www.17dst.com/gongju/gongju_01.html

等等

同时,我们还可以更进一步的优化
RewriteRule ^index\.html$
表示:永久重定向到不带index.html的地址

dywe12 发表于 2010-7-16 22:40:29 | 显示全部楼层
人家是版主!还是……
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-9-28 14:17 , Processed in 0.901158 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表