解除转换后的流量丢失之——全面Rewrite规则_PhpWind教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

 

之前写过一个PHPWind保持Dz转换后的搜索引擎带来的流量之rewrite 规则 ,当时对此方面知识尚未深刻了解,局限性太强,今天就全面的写下转换后的几个rewriterule。

主要以这么5个Discuz!,DVBBS,LEOBBS,LEADBBS,BBSXP,,需要更多可以提出来,我帮你写,或者根据这个思路逐渐修改。
参考资料:http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html  欢迎大家一起来~!~

我的平台是 Apache/2.2.4 (Win32) ,IIS的伪静态规则和apache可以通用, zeus和Nginx规则有些变化,但用的人比较少后面有时间再讲
先针对的是有独立主机权限的用户请注意,高级重写(要写绝对目录,这里举例用/bbs/,请根据实际情况更改):

DZ转换过来的。~【有独立服务器的站长,重写规则出错可以找官方侠客,或者找PM我一起解决】

请先做一下步骤:

把thread.php复制一份改名为forumdisplay.php
把read.php复制一份改名为viewthread.php 

这样省事省时,保证动态地址访问正常,接下去开始伪静态重写规则

RewriteRule ^(.*)/archiver/$         [R]



# 适用于.htaccess和httpd.conf
RewriteEngine On
RewriteRule ^(.*)/archiver/         /simple/   [R]
RewriteRule ^(.*)/tid-(\d+)\.html   /simple/index.php?t$2.html [R]
RewriteRule ^(.*)/fid-(\d+)\.html  /simple/index.php?f$2.html [R]
RewriteRule ^(.*)/fid-(\d+)-(\d+)-1.html  /simple/index.php?f$2.html [R]
RewriteRule ^(.*)/forum-(\d+)-(\d+)\.html$  $1/thread.php?fid=$2   [R]
RewriteRule ^(.*)/thread-(\d+)-(\d+)-(\d+)\.html$ $1/read.php?tid=$2   [R]
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]

老版本如果不能实现伪静态,可以尝试一下规则

# httpd.ini  在Rewrite的不同版本
RewriteRule ^(.*)-htm-(.*)$   $1\.php\?$2
RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC]

然后重启IIS或者apache.

或者用下面


       RewriteEngine On
        RewriteCond %{SCRIPT_FILENAME} ^/bbs/forumdisplay.php$  [OR]
        RewriteCond %{SCRIPT_FILENAME} ^/bbs/viewthread.php$  [NC]
        RewriteCond %{QUERY_STRING} fid=(\d+) [OR]
        RewriteCond %{QUERY_STRING} tid=(\d+) [NC]
        RewriteRule (.*)  /%{QUERY_STRING} [NC]
        RewriteRule ^/fid=(\d+)   /bbs/thread.php?fid=$1 [R]
        RewriteRule ^/tid=(\d+)   /bbs/read.php?tid=$1 [R]
        RewriteCond %{SCRIPT_FILENAME} ^/bbs/archiver/$  [NC]
        RewriteCond %{QUERY_STRING} tid-(\d+).html [OR]
        RewriteCond %{QUERY_STRING} fid-(\d+).html [NC]
        RewriteRule (.*)  /%{QUERY_STRING} [NC]
        RewriteRule ^/tid-(\d+).html   /bbs/simple/index.php?t$1.html [R]
        RewriteRule ^/fid-(\d+).html   /bbs/simple/index.php?f$1.html [R]
        RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$  $1/thread.php?fid=$2
        RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/read.php?tid=$2
        RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
        RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]
      

ZUes的伪静态

match URL into ^(.*)/forum-([0-9]+)-([0-9]+)\.html$
if matched then
set URL = $1/thread.php?fid=$2
endif
match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$
if matched then
set URL = $1/read.php?tid=$2
endif
match URL into $ with ^(.*)-htm-(.*)$
if matched then
set URL = $1.php?$2
endif
match URL into $ with ^(.*)/simple/([a-z0-9\_]+\.html)$
if matched then
set URL = $1/simple/index.php?$2
endif

DVBBS转换过来的
1\IIS的httpd.ini

[ISAPI_Rewrite]
RewriteEngine On
CacheClockRate 3600
RepeatLimit 32
RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
RewriteRule ^(.*)/dispbbs.asp\?boardid=(\d+)&Id=(\d+)  $1/read.php?tid=$3 [NC]
RewriteRule ^(.*)/dispbbs.asp\?boardid=(\d+)&id=(\d+)  $1/read.php?tid=$3 [R]
RewriteRule ^(.*)/dispbbs.asp\?BoardID=(\d+)&Id=(\d+)  $1/read.php?tid=$3 [R]
RewriteRule ^(.*)/index.asp\?boardid=(\d+)  $1/thread.php?fid=$2 [R]
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]
#Code By Josh @ PHPWind 2008-09-25 ?([a-zA-Z]+)

2、apache


    RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} ^/bbs/index.asp$  [NC]
RewriteCond %{QUERY_STRING} boardid=(\d+)$ [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/boardid=(\d+)$ /bbs/thread.php?fid=$1 [R]
RewriteCond %{SCRIPT_FILENAME} ^/bbs/dispbbs.asp$  [NC]
RewriteCond %{QUERY_STRING} boardid=(\d+)&Id=(\d+) [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/boardid=(\d+)&Id=(\d+)  /bbs/read.php?tid=$2 [R]
    RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
    RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]


LEOBBS转换过来的


    RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} ^/bbs/cgi-bin/forums.cgi$  [NC]
RewriteCond %{QUERY_STRING} forum=(\d+)$ [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/forum=(\d+)$   /bbs/thread.php?fid=$1 [R]
RewriteCond %{SCRIPT_FILENAME} ^/bbs/cgi-bin/topic.cgi$  [NC]
RewriteCond %{QUERY_STRING} forum=(\d+)&topic=(\d+) [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/forum=(\d+)&topic=(\d+)  /bbs/read.php?tid=$2 [R]
    RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
    RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]


BBSXP转换过来的


    RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} ^/bbs/ShowForum.asp$  [NC]
RewriteCond %{QUERY_STRING} ForumID=(\d+) [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/ForumID=(\d+)   /bbs/thread.php?fid=$1 [R]
RewriteCond %{SCRIPT_FILENAME} ^/bbs/ShowPost.asp$  [NC]
RewriteCond %{QUERY_STRING} ThreadID=(\d+) [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/ThreadID=(\d+)  /bbs/read.php?tid=$1 [R]
    RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
    RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]


LEADBBS转换过来的


    RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} ^/bbs/b/b.asp$  [NC]
RewriteCond %{QUERY_STRING} B=(\d+) [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/B=(\d+)   /bbs/thread.php?fid=$1 [R]
RewriteCond %{SCRIPT_FILENAME} ^/bbs/a.asp$  [NC]
RewriteCond %{QUERY_STRING} B=(\d+)&ID=(\d+) [NC]
RewriteRule (.*)  /%{QUERY_STRING} [NC]
RewriteRule ^/B=(\d+)&ID=(\d+)  /bbs/read.php?tid=$2 [R]
    RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
    RewriteRule ^(.*)simple/([t|f].+).html$ /simple/index.php?$2.html [NC,L]



无独立服务器权限的做法:

分两种情况,一是支持.htaccess,一种是不支持伪静态的虚拟空间。
对于支持.htaccess的空间,可以套用转发规则进行处理.

无法用重写的,我们用文件来补救

DZ:
把thread.php复制一份改名为forumdisplay.php
把read.php复制一份改名为viewthread.php

这样省事省时,哈哈,祝大家愉快!

DVBBS:
如果你的服务器还支持ASP的话
可以在index.asp和dispbbs.asp上面做下。

 

查看更多 PhpWind教程  PhpWind模板风格

来源:Phpwind//所属分类:PhpWind教程/更新时间:2009-11-24
相关PhpWind教程