[原创]创建Lighttpd伪静态规则

今天有位朋友问我怎么在Lighttpd中部署PhpWind的伪静态规则,由于我没有使用过PhpWind的程序,所以我并不清楚他的伪静态规则是怎么样的,这里就用Discuz的伪静态规则讲解一下应该怎么修改才能使Lighttpd也能支持Discuz的伪静态。使用其他程序配置伪静态按照这个思路走过来也就对了。

首先我们打开.htaccess,如果没有找到,可以在用户手册那里找到规则。

# 将 RewriteEngine 模式打开
RewriteEngine On

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

# Rewrite 系统规则请勿修改
RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
RewriteRule ^tag-(.+).html$ tag.php?name=$1

我们就把一些在lighttpd中不需要使用的删除,比如RewriteEngine On,RewriteBase /discuz和那些没用的说明,我们只需要保留RewriteRule里面的内容。删除后就只剩下下面这些了。

RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
RewriteRule ^tag-(.+).html$ tag.php?name=$1

Sponsored Links

紧接着,我们需要做的就是将规则转换成在lighttpd中支援的类似perl hash声明的字串即可。
我们删除所有列前面的 RewriteRule 和空格,将列的最前面^修改为"^(.*)/,然后将中间的空格替换成" => "$1/,然后在最后添加";。全部列搞定之后,我们将要对=>右边的内容进行修改,将原来的$1修改为$2,$2修改为$3,依此类推,最后我们用一个括号将这些语句包围起来。然后在括号前添加url.rewrite-once = ,然后将这个规则放入虚拟主机的大括号中就可以了。

下面是配置好的lighttpd的Discuz伪静态规则

$HTTP["host"] =~ "^bbs.youdomain.com$" {
url.rewrite-once = (
"^(.*)/archiver/((fid|tid)-[w-]+.html)$" => "$1/archiver/index.php?$2",
"^(.*)/forum-([0-9]+)-([0-9]+).html$" => "$1/forumdisplay.php?fid=$2&page=$3",
"^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$" => "$1/viewthread.php?tid=$2&extra=page%3D$4&page=$3",
"^(.*)/space-(username|uid)-(.+).html$" => "$1/space.php?$2=$3",
"^(.*)/tag-(.+).html$" => "$1/tag.php?name=$2"
)
}

最后,重启一下Lighttpd服务器即可。

注:如果程序放在目录里,比如程序放在discuz这个目录,那么我们就需要在规则里进行修改,如上面的例子,我们只要将"^(.*)/修改为"^(.*)/discuz/,将"$1/修改为"$1/discuz/即可。
匆忙中写下此文,如果以上有差错,请与我取得联系。我明天会再测试,现在要去睡觉了。呵呵。

文章转载自:诡谲翳影的博客

标签:

留下回复

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: