[英]Apache mod_rewrite to lighttpd
我正在尝试将 PHP 项目从 apache 转移到 lighttpd。 我在 apache 中有以下重写:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !\.(js|ico|gif|jpg|jpeg|png|css|ttf)$ /index.php?_url=/$1 [QSA,L]
我无法将它翻译成 lighttpd mod_rewrite。
以下是我的一些尝试:
url.rewrite-if-not-file = (
# try with two separate matches - when the request ends with file.ext
"\.(?!(js|ico|gif|jpg|jpeg|png|css|ttf))[\?]{0,1}(.*)$" => "/index.php?_url=/$1",
# if the request ends with /
"/[\?]{0,1}$" => "/index.php?_url=/"
# ".+/(.*)?(.*)" => "/index.php?_url=/$1",
# "((?!\.(js|ico|gif|jpg|jpeg|png|css|ttf)).*)" => "/index.php?_url=/$1"
# "^([^\?(js|ico|gif|jpg|jpeg|png|css|ttf)]+)[\?]{0,1}(.*)$" => "/index.php?_url=$1&$2"
)
与上一个版本的唯一区别是我看到 PHP 的 $_SERVER['SCRIPT_NAME'] 的唯一区别。 它是: [SCRIPT_NAME] => /v1/en/entity/method/ # 使用 apache [SCRIPT_NAME] => /index.php # 使用 lighttpd
首先,您必须将此代码放在/etc/lighttpd/conf-enabled/10-rewrite.conf
之后server.modules += ("mod_rewrite")
或在相应 vhost 的/etc/lighttpd/conf-enabled/90-vhosts.conf
中(分别在 conf-available 和指向 conf-enabled 的符号链接)
你不能把它放在 .htaccess
但是好吧,让我们承认这是域 www.example.com
http['HOST'] == "www.example.com"{
// rewrite the url if there is no such file and
url.rewrite-if-not-file = (
"^(.*)!\.(js|ico|gif|jpg|jpeg|png|css|ttf)$" => "/index.php?_url=/$1"
)
}
这应该与 Apache 中的工作方式相同。
(我没有测试过)
$HTTP["host"] == "www.example.com" {
# rewrite the url if there is no such file and not a listed extension
url.rewrite-if-not-file = (
"\.(?:js|ico|gif|jpg|jpeg|png|css|ttf)$" => "",
".*" => "/index.php?_url=$0"
)
}
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRewrite
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.