Project

General

Profile

[UE] url.rewrite-if-not-file in a condition

Added by doerner almost 5 years ago

I experience the following behavior (with loaded module mod_rewrite):

$HTTP["useragent"] =~ "Safari" {
url.rewrite-if-not-file = ("A" => "B")
}

does not work / rewrite.
But working is

url.rewrite-if-not-file = ("A" => "B")

as well as

$HTTP["useragent"] =~ "Safari" {
url.rewrite = ("A" => "B")
}

(of course "A" (and "B") are other / longer / more complex expressions in my use case)

I use Lighttpd 1.4.52 on alpine linux.
Can anyone please confirm that the most above code is working on his system?
Thank you.


Replies (1)

RE: url.rewrite-if-not-file in a condition - Added by gstrauss almost 5 years ago

x-ref: #2952

The example you provided was obviously not tested by you, since it is invalid. lighttpd 1.4.50 and later reject any mod_rewrite results which returns a path which does not being with '/'. Your 'B' replacement does not begin with '/'. If you post an example asking "does this work", then you ought to have tested it yourself, exactly as you have posted.

lighttpd 1.4.52 on Fedora 30 on amd64 works with the following:

$ mkdir /tmp/you-should-test-better
$ echo hi > /tmp/you-should-test-better/B
With a test-lighttpd.conf containing:

server.port = 8080
server.document-root = "/tmp/you-should-test-better" 
server.modules += ("mod_rewrite")
$HTTP["useragent"] =~ "Safari" {
  url.rewrite-if-not-file = ("/A" => "/B")
}

$ lighttpd -f test-lighttpd.conf -D &
$ curl -H "User-Agent: Safari" http://127.0.0.1:8080/A
$ curl http://127.0.0.1:8080/A
$ kill %1
$ rm -rf /tmp/you-should-test-better/

    (1-1/1)