Deth

Fitness and everything else

Caddy Redirects

I decided that I wanted to move my fitness related stuff into the wiki folder. The only reason really was to keep he public_html directory clearing and better organized.

I wanted to set up a quick 302 redirect in Caddy so that any links to the old stuff will get redirected to the new URL instead of just a 404.

I could have and did set up individual redirects at first but I got to thinking that there has to be a better way that is cleaner and could be useful in the future if I move things around. I knew I needed to use a request matcher to do that. When looking into it I saw the perfect solution. Caddy has a .startsWith option which is exactly what I needed since they all started with “fitness” in the file path.

@fitness `{path}.startsWith("/fitness/")`

Now that the matcher is set up I could go ahead and do the redirect. That was easy enough since the path is the same except for the “/wiki” added at the beginning.

redir @fitness /wiki/{path} permanent

It worked like a charm and gave me another way to look at it rather than individual redirects or trying to play with regex. This option is just more readable to me at a quick glance than some of the other solutions would have been..