Apache mod_rewrite to lighttpd

问题描述 投票:1回答:1

我想把一个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] => v1enentitymethod #用apache[SCRIPT_NAME] => index.php #用lighttpd。

请求本身是https:/api.localv1enentitymethod

php regex apache mod-rewrite lighttpd
1个回答
0
投票
$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=$0"
    )
}

https:/redmine.lighttpd.netprojectslighttpdwikiDocs_ModRewrite。


0
投票

首先你必须把这段代码放在 /etc/lighttpd/conf-enabled/10-rewrite.conf 之后 server.modules += ("mod_rewrite") 或在 /etc/lighttpd/conf-enabled/90-vhosts.conf 在相应的vhost(分别在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的工作方式一样。(我还没有测试)

© www.soinside.com 2019 - 2024. All rights reserved.