Different rewrites for root and paths

This is bit weird. Okay, so this what I am trying to achieve.

Root Level

When user enters:
It should get rewritten as

*** Path Level***
When user enters:
It should get rewritten as

**How I’m doing it now. **
rewrite / /{host} → This works properly for the root
rewrite / (star) /{host}{uri} → This will override the above rule

How to achieve the rewrite for both cases?

PS: Just discovered Caddy 2 days ago.

G’day @joanna, welcome to the Caddy community!

Based on what you’ve written as the intended rewrite results, the method you’ve got (one rewrite for each case) should be the best way to go about it.

One rewrite alone probably won’t be suitable, since rewrite * /{host}{uri} will produce https://example.com/example.com/ (with a trailing slash) for the first case (a request to the web root), when you’ve said that you want https://example.com/example.com (no trailing slash).

Is there any specific problem with the way you’ve said you’re doing it right now? It looks alright to me at a glance (assuming it’s formulated properly in the Caddyfile itself, i.e. without the spacing between / and your (star)).


Thank you @Whitestrake. We have changed the implementation. Based on my test, they produce different results,

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