让lighttpd支持WordPress的ReWrite固定链接

首先,修改 /etc/lighttpd/lighttpd.conf 激活 mod_rewrite 模块。格式如下:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite",
)

方法一:

然后在 /etc/lighttpd/conf-enabled/10-simple-vhost.conf 内添修改如下:
$HTTP["host"] == "rex.zhang.name" {
server.document-root = "/www/"
accesslog.filename = "/var/log/lighttpd/rex.zhang.name.access.log"
...
...
url.rewrite = (
"/wp-admin/$" => "/wp-admin/index.php",
"^/(.*).(.+)$" => "$0",
"^/(.+)/?$" => "/index.php/$1"
)
}

确保网站根目录下的 .htaccess 文件存在,并且在文件权限上可以被执行 lighttpd 的用户可写。最后在 /wp-admin/options-permalink.php 设计自己喜欢的目录格式即可。成功后的 .htaccess 文件内容如下
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]

最后重启 web 服务器即可。

方法二:

lighttpd最新版在/etc/lighttpd/lighttpd.conf中增加

url.rewrite = ( "^/(archives|categories|comments|feed)/" => "/index.php" )

举例,默认站点:

$SERVER["socket"] == ":80" {
server.document-root = "/var/www/html"
url.rewrite = ( "^/(archives|categories|comments|feed)/" => "/index.php" )
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注