我正在尝试在 lighttpd 下启动并运行 vBulletin 5,但在 URL 重写方面遇到了一些问题。这是 vBulletin 提供的 apache .htaccess。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?routestring=$1 [L,QSA]
#needed because admincp is an actual directory.
RewriteRule ^(admincp/)$ index.php?routestring=$1 [L,QSA]
</IfModule>
如果有帮助的话,这是 vBulletin 提供的 IIS 配置
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is to support redirection in IIS. It is harmless if you are running under Apache -->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Redirect" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
<rule name="Admincp" stopProcessing="true">
<match url="^(admincp/)$" ignoreCase="false" />
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
有人对 lighttpd url.rewrite 等效方法有什么建议吗?到目前为止,我的所有实验都失败了。
我正在运行 lighttpd-1.4.31-1
我试过了,但没用。我认为这与我没有在 .htaccess 中正确模拟 [QS] 有关
url.rewrite-once = ("^(.*)$" => "index.php?routestring=$1",
"^(admincp/)$)" => "index.php?routestring=$1")
这使我更接近了,但尚未完全发挥作用。
url.rewrite-if-not-file = ("^(.*)$" => "index.php?routestring=$1",
"^(admincp/)$)" => "index.php?routestring=$1")
答案1
正则表达式应用于整个请求 URI,包括查询字符串,因此您需要明确处理尝试这样的操作:
url.rewrite-if-not-file = (
"^/([^\?]+)(\?(.*))?$" => "index.php?routestring=$1&$3",
)
url.rewrite-once = (
"^/(admincp/[^\?]+)(\?(.*))?$" => "index.php?routestring=$1&$3",
)
第二个/admincp/
可能没有必要,因为rewrite-if-not-file
与目录不匹配。