That does not entirely “make sense”
as I am not a Caddy dev, but the route
block does the magic indeed: the rewrite directives are now executed in the order they are written in the Caddyfile.
route {
@underscore path_regexp u ^([^_]+)_(.+)$
rewrite @underscore {re.u.1}-{re.u.2}
@shortUrl path_regexp s ^([^.]+)$
rewrite @shortUrl {re.s.1}.html
}
I think I start to see the light, but I am not there just yet! As for the log level debug
, for a URI like foo_bar
, the file foo-bar.html
is now served correctly, but I can not see the rewrite happen in the log that I have set to level debug
as you can see in my sample Caddyfile above. The only entry I have :
{
"level": "info",
"ts": 1601985110.6761084,
"logger": "http.log.access.log1",
"msg": "handled request",
"request": {
"remote_addr": "192.168.0.92:49956",
"proto": "HTTP/1.1",
"method": "GET",
"host": "test.gaubert",
"uri": "/foo_bar",
"headers": {
"Connection": [
"keep-alive"
],
"Upgrade-Insecure-Requests": [
"1"
],
"Accept-Language": [
"en-GB,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,fr-BE;q=0.6,nl;q=0.5"
],
"Pragma": [
"no-cache"
],
"Cache-Control": [
"no-cache"
],
"User-Agent": [
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
],
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
],
"Accept-Encoding": [
"gzip, deflate"
]
}
},
"common_log": "192.168.0.92 - - [06/Oct/2020:13:51:50 +0200] \"GET /foo_bar HTTP/1.1\" 200 25",
"duration": 0.00116073,
"size": 25,
"status": 200,
"resp_headers": {
"Last-Modified": [
"Tue, 06 Oct 2020 11:50:44 GMT"
],
"Accept-Ranges": [
"bytes"
],
"Content-Length": [
"25"
],
"Server": [
"Caddy"
],
"Etag": [
"\"qhs3kkp\""
],
"Content-Type": [
"text/html; charset=utf-8"
]
}
}