[英]Apache mod_rewrite to lighttpd
I'm trying to transfer a PHP project from apache to lighttpd.我正在尝试将 PHP 项目从 apache 转移到 lighttpd。 I have the following rewrite in the apache:
我在 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]
I can't manage to translate it to lighttpd mod_rewrite.我无法将它翻译成 lighttpd mod_rewrite。
Here are some of my attempts:以下是我的一些尝试:
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"
)
With the last version the only difference I see the only difference in PHP's $_SERVER['SCRIPT_NAME'].与上一个版本的唯一区别是我看到 PHP 的 $_SERVER['SCRIPT_NAME'] 的唯一区别。 It is: [SCRIPT_NAME] => /v1/en/entity/method/ # with the apache [SCRIPT_NAME] => /index.php # with the lighttpd
它是: [SCRIPT_NAME] => /v1/en/entity/method/ # 使用 apache [SCRIPT_NAME] => /index.php # 使用 lighttpd
The request itself is: https://api.local/v1/en/entity/method/请求本身是: https://api.local/v1/en/entity/method/
first of all you must place this code in /etc/lighttpd/conf-enabled/10-rewrite.conf
after首先,您必须将此代码放在
/etc/lighttpd/conf-enabled/10-rewrite.conf
之后server.modules += ("mod_rewrite")
or in the /etc/lighttpd/conf-enabled/90-vhosts.conf
at the corresponding vhost (respectively in the conf-available and point a symlink to conf-enabled)或在相应 vhost 的
/etc/lighttpd/conf-enabled/90-vhosts.conf
中(分别在 conf-available 和指向 conf-enabled 的符号链接)
you cannot place it in .htaccess你不能把它放在 .htaccess
BUT OK lets admit this is the domain www.example.com但是好吧,让我们承认这是域 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"
)
}
this should work the same way as in Apache.这应该与 Apache 中的工作方式相同。
(I haven't tested it) (我没有测试过)
$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 https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRewrite
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.