Removing dynamic prefix (dates) from URI

Oh, so you want a redirect, not a rewrite. Use the redir directive for that, then.

A rewrite is transforming/changing the URL before it gets passed to subsequent handlers. That doesn’t change the URL in the browser.

A redirect is writing a response back to the client with the Location header set which tells the client “try again, but at this URL instead”. That changes the URL you see in the browser.

Either way, that regexp is probably incomplete for your needs. You’ll want to expand on that to cover other date patterns. You can play with regular expressions at https://regex101.com/ and pick the Golang variant in the sidebar, which Caddy uses.

2 Likes