官方文档写得很简单.它给的例子没那么简单了:
url.rewrite-once = ( "^/id/([0-9]+)$" => "/index.php?id=$1",
"^/link/([a-zA-Z]+)" => "/index.php?link=$1" )# the following example, is, however just simulating vhost by rewrite
# * you can never change document-root by mod_rewrite
# use mod_*host instead to make real mass-vhost# request: http://any.domain.com/url/
# before rewrite: REQUEST_URI="/www/htdocs/url/"
# and DOCUMENT_ROOT="/www/htdocs/" %0="any.domain.com" $1="url/"
# after rewrite: REQUEST_URI="/www/htdocs/any.domain.com/url/"
# still, you have DOCUMENT_ROOT=/www/htdocs/server.document-root = "/www/htdocs/"
$HTTP["host"] =~ "^.*\.([^.]+\.com)$" {
url.rewrite-once = ( "^/(.*)" => "/%0/$1" )
}
官方指出lighttpd与apache的rewrite的完全不同,它给的例子是:
Apache:
RewriteEngine On
RewriteBase /instadir/
RewriteCond %{REQUEST_FILENAME} -d
# Fix trailing slash problem
RewriteRule ^(.+[^/])$ $1/ [R,L]
# Do not try to treat the following resources as parameters to index.php
RewriteRule ^index.php.*$ - [L]
RewriteRule ^dmoz.css$ - [L]
RewriteRule ^admin[/]?.*$ - [L]
RewriteRule ^img[/]?.*$ - [L]
RewriteRule ^[/]{0,}(.*)$ index.php?area=browse&cat=$1 [QSA,L]
Lighttpd:
## for all URLs in /instadir/ that are not index.php, dmoz.css, admin or img, do ...
url.rewrite-once = ( "^/instadir/(?!index.php|dmoz.css|admin|img).*" => "$0",
"^/instadir/([^?]*)(?:\?(.*))?" => "/instadir/index.php?area=browse&cat=$1&$2")
这里有一篇实战文章,可以做为参考.
WordPress 的 permallink 需要 apache 的支持,wordpress 会自动生成一个 .htaccess 文件来给 apache 加 rewrite 规则,但是 lighttpd 的 rewrite 规则格式和 apache 不一样,而且好像不支持 .htaccess. 需要手动转换一下。
WordPress 生成的 .htaccess 规则大概是
RewriteBase /wordpress/
RewriteRule ^.*$ index.php [S=47]
RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /wordpress/index.php?&feed=$1 [QSA,L]
RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /wordpress/index.php?&feed=$1 [QSA,L]这样的
lighttpd 需要的rewrite规则大概是
url.rewrite = (”^/wordpress/feed/(feed|rdf|rss|rss2|atom)/?$” => “/wordpress/index.php?&feed=$1″,
“^/wordpress/(feed|rdf|rss|rss2|atom)/?$” => “/wordpress/index.php?&feed=$1″,
“^/wordpress/page/?([0-9]{1,})/?$” => “/wordpress/index.php?&paged=$1″
)这样的
内容和 Apache 的基本类似,就是把所有规则转换成一个 perl hash 声明类似的字串就可以了。
这里可以用程序来作,但是我懒得写程序,直接用 UltraEdit 的列模式和替换就可以了:首先删除
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ index.php [S=47]这些对 lighttpd 之类不需要的内容。
然后 UE 切换成列模式,删除所有列前面的 RewriteRule 和空格
在最前面插入 “/wordpress/
这样就把 RewriteBase 的内容包括进来了,如果没有 RewriteBase 的话,直接插入一个双引号就可以了接下来用全文替换将最后的 [QSA,L] 和之前的一个空格替换成引号和逗号 “,
现在文本里面就只剩下规则中间的那个空格了,用全文替换将这个空格替换成 “=>”
最后手动编辑一下,最后一行的逗号删掉改成 )
第一行最前面加 url.rewrite = (lighttpd 需要的 rewrite 规则就写完了,将这个文本的内容保存为 wprewrite.conf
然后在 lighttpd.conf 里面 include “wprewrite.conf”重启 lighttpd 搞定
请教前辈我站www.iccd.cc上lighttpd的rewrite规则:
这是url.rewrite-once = (
“^/(.*)?/?files/$” => “index.php”,
“^/(.*)?/?files/(.*)” => “wp-content/blogs.php?file=$2”,
“^/(wp-.*)$” => “$1”,
“^/([_0-9a-zA-Z-]+/)?(wp-.*)” => “$2”,
“^/([_0-9a-zA-Z-]+/)?(.*\.php)$” => “$2”,
“(\?.*)$” => “index.php$1”,
“.” => “index.php”
现在连接都能打开页面,但就是手动上传的文件都打不开,比如根目录下建立文件夹/images,但我怎么也读取不了这里面的图片文件,痛苦不堪!!
感谢你,赵兄,尽管问题没有解决,但是还是要谢谢你,特别是你的文章,写的很棒,指导性很强。
谢谢你的回答,我测试过了,discuz规则用url.rewrite-once ,wordpress规则用url.rewrite,可以配置成功的,但是估计是wordpress的子目录问题,子目录bbs依然打不开,一直显示wp的404,所以论坛依然不能使用。
是,wp的rewrite问题.俺不是技术流的,不知道咋解决的.
赵兄,你好,我这里有一个问题想咨询一下,在lighttpd支持rewrite中我找出了discuz的规则与wordpress的规则,分开用时都没有问题,但是我在一vps中需要同时用到,找了好多天依然没有找到解决办法,您能否给点提示呢?
你把wp不用rewrite.以前有个案例是plogger和wp不能同时rewrite.具体原因没查过.
支持楼主成为一个技术型的纽曼。
有好看的表情符号吗?
:em16: 换什么表情了
我靠,最近怎么都是技术贴啊