Rewrite uppercase to lowercase (port rewrite rule from Apache to Caddy)

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

a. System environment:

Docker on Linux.

3. The problem I’m having:

I run a static website that has some issues with capitalization in the URI’s in the HTML code. It’s a very old site that used to run on a Windows machine and in that environment there was no distinction between upper- and lowercase characters so it worked fine.

I’m now running it on a Linux machine with Apache and to make it work I rewrite all request URI’s to lowercase. I would like to do the same with Caddy, is that possible?

In my Apache config the rewrite rule looks like this:

# Rewrite all requests to lowercase
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/?(.*)$ /${lowercase:$1} [R=301,L]

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

1 Like

Hmm, unfortunately I don’t think there’s anything built into Caddy to do this (unfortunately I don’t think regexp is smart enough for this).

But it would probably be trivial to implement a custom module to do it.

Yeah, a lowercasing module would take like 5 minutes to write. (Copy paste the boilerplate, modify a few lines, boom done.)

Thanks for the info guys! I can imagine it will be easy to implement for somebody with a bit of Go and programming experience. Unfortunately I’ve never done anything in Go and I’m not much of a programmer. At least now I know I don’t have to spend more time looking into a solution with Caddy’s uri + regex.

This topic was automatically closed after 30 days. New replies are no longer allowed.