Apache mod_rewrite 到 lighttpd
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=/ [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=/",
# if the request ends with /
"/[\?]{0,1}$" => "/index.php?_url=/"
# ".+/(.*)?(.*)" => "/index.php?_url=/",
# "((?!\.(js|ico|gif|jpg|jpeg|png|css|ttf)).*)" => "/index.php?_url=/"
# "^([^\?(js|ico|gif|jpg|jpeg|png|css|ttf)]+)[\?]{0,1}(.*)$" => "/index.php?_url=&"
)
与上一个版本的唯一区别是 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")
或在相应虚拟主机的 /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=/"
)
}
这应该与 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=[=10=]"
)
}
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRewrite
我正在尝试将一个 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=/ [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=/",
# if the request ends with /
"/[\?]{0,1}$" => "/index.php?_url=/"
# ".+/(.*)?(.*)" => "/index.php?_url=/",
# "((?!\.(js|ico|gif|jpg|jpeg|png|css|ttf)).*)" => "/index.php?_url=/"
# "^([^\?(js|ico|gif|jpg|jpeg|png|css|ttf)]+)[\?]{0,1}(.*)$" => "/index.php?_url=&"
)
与上一个版本的唯一区别是 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")
或在相应虚拟主机的 /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=/"
)
}
这应该与 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=[=10=]"
)
}
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRewrite