Rewrite to external site

Hello, I’m new to caddy here, and so far have been amazed at the ease of setup, but there’s something I can’t quite figure out how to do. I want to rewrite (I think) a subdomain to an external site. For example, someone visits and they’ll see whatever is at, but without getting redirected.

I tried

blog. example .com:80 {
      rewrite / {
           to http://exampleblog. com:80
      tls off

The redirect below does work, but I don’t want the user to be able to see the redirect, and would prefer it happen all in the background.

blog. example. com:80 {
      redir http:// exampleblog .com

I’m not sure rewrite is exactly what I want, but after some searching online it was the closest I could find.

Thanks for any help!

Hi @Addison_Bostian, welcome to the Caddy community.

It actually sounds like what you want is a reverse proxy - that is, you connect to Caddy, Caddy goes and fetches whatever is at the external site and returns it to you - no redirections, and you see the subdomain you put in originally, not the external site address.

Check out the proxy directive:

1 Like

Hello @Whitestrake,
Ah, okay. Thank you for that! So after reading that example, reverse proxy worked like a charm for http, but not quite for https, but I think that it’s actually a port forwarding issue now.

Thank you so much for your help!

1 Like

Update: It was definitely a port forwarding issue. Apparently my router won’t forward 443. So caddy’s reverse proxy works flawlessly.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.