I’m not sure I understand the difference between the two structures below. Is the end result the same for both, or, is there something subtle happening here that I’m not appreciating?
Okay. I guess I’m not fully understanding the difference between redirect and serve in this context. For the casual user browsing www.domain.com, I assume the effect will be the same. They are none the wiser to what they’re seeing returned in the browser window.
To help me develop a deeper understanding, a follow-up question please… ‘In what context is one approach preferred over the other?’
The difference is that when the content is served on www, the browser will still show www in the address bar. With a redirect, the first request will tell the browser “no, go over there” and then the content will be served, but without www in the address bar.
Generally it’s better to only have one singular domain from which content is served from for SEO and such, I think, cause otherwise it can look like duplicate content from two different domains. But I’m no SEO expert so take that with a grain of salt.
Based on as always helpful advice I received from @francislavoie in this thread, I’ve begun to move away from multisite definition and towards redirection. A noob question about {uri}…
An extract from the redir documentation, specifically the examples.
I try leaving out {uri} and the redirection still works, so, by including it, what does ‘preserve the existing URI’ actually achieve? If I add in the permanent switch, how does that change again? I’d like to understand these subtleties please.
Basically having {uri} will make a request to http://www.example.com/some/path redirect to https://example.com/some/path, whereas if you remove {uri} it would redirect to https://example.com, i.e. lose the path portion. It’s nicer for users if they clicked a link from somewhere else to actually go to the page they wanted to go to when redirecting, instead of throwing them back to the root of the site.
Adding permanent changes the HTTP status code used in the redirect response. As noted in the docs, the default is “temporary”, i.e. 302. The difference is that a 301/permanent redirect will be remembered by the browser to avoid the extra roundtrip, and also any bots/crawlers might use that to determine that forget the old URL and only keep the final destination. Just google “difference between 301 and 302” and you’ll find plenty of explanations.
I’ve shied away from SEO, but it’s beginning to dawn on me a lot of the tuning that can be done in Caddy helps with SEO. This is previously uncharted territory for me.
If you had the redirect marked the other way around and the browser cached it, then it might be causing you to run in a loop. Or maybe the site you’re serving is doing its own redirect.
You can run curl -v to see what the response to the redirect looks like – see the Location: header to see what the value is.
Not enough info to go on from what you wrote so far to know exactly what the problem is.