Apache mod_rewrite для lighttpd - PullRequest
       101

Apache mod_rewrite для lighttpd

1 голос
/ 17 июня 2020

Пытаюсь перенести проект 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"
    )

С последней версией единственное отличие Я вижу единственное различие в $ _SERVER ['SCRIPT_NAME'] PHP. Это: [SCRIPT_NAME] => / v1 / en / entity / method / # с apache [SCRIPT_NAME] => /index.php # с lighttpd

Сам запрос: https://api.local/v1/en/entity/method/

Ответы [ 2 ]

0 голосов
/ 17 июня 2020
$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

0 голосов
/ 17 июня 2020

в первую очередь вы должны поместить этот код в /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.
(не тестировал)

...