Redirect with changed uri

I’m trying to find a way to redirect with changing uri on the fly.

It’s easy task:
site.com/old/__any_path
301 redirect to
archive.site.com/__any_path

hanlde_path and uri doesn’t help because they don’t redirect.
If use usual redirect than it gets uri and the result is:
archive.site.com/old/__some_path

Sorry if it already was questioned but I didn’t find clear answer about right way to do it.

You’ll want a path_regexp matcher here probably.

site.com {
	@old path_regexp old ^/old/(.*)
	redir @old https://archive.site.com/{re.old.1}{query} 301
}

Yep, it works. Thank you!

One small question — what is {re. Is it cut from ‘regexp’? Didn’t find it in the documentation

It’s a placeholder shortcut available in the Caddyfile. re is short for “regular expression”

1 Like

Thanx! Very useful!

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