Redirect to subdomain, partial different URI

1. Caddy version (caddy version):

2.5.1

2. How I run Caddy:

systemd

a. System environment:

Debian 10

b. Command:

systemctl start caddy

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

Paste config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
LEAVE DOMAIN NAMES INTACT.
Make sure the backticks stay on their own lines.

3. The problem I’m having:

I can’t redirect or rewrite uri to subdomain

origin link: https://abc.com/category/test/product1

need to rewrite or redirect to: https://test.abc.com/group/product1

Please help me how to get it works.
Thank you.

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Use a path_regexp matcher to capture the part of the URL you want to keep, then you can use the regexp matches when writing the target URL.

abc.com {
	@oldUrl path_regexp old /category/test/(.*)
	redir @oldUrl https://test.abc.com/group/{re.old.1}
}

You can play around with https://regex101.com/ (pick the Golang flavor) to play with the regexp to get it to do what you want.

2 Likes

Great. It works with your config.
Thanks so much.

2 Likes

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