Forum Moderators: phranque
...links to the very same page that has already loaded.
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteCond %{HTTP_HOST} !^www\.example\.com$
you shouldn't be making this pattern optional
It is possible to set browsers to "warn" if sites attempt to redirect.
I have personally never met a request missing this header field; even the minimalist three-line block-on-sight robots (the ones that don't send User-Agent or Accept headers) include it. So it does no harm, but has probably outlived its usefulness.
...user-agents that don't sent the "Host:" header.
there are several text-based browser such as w3m and I believe lynx as well that implement HTTP/1.0 protocol.
these user agents are often the front end for web accessibility tools, so consider carefully what ignoring these user agents implies...
...how else would things on a shared server end up in the right place?
So, it would seem that for a valid HTTP client to make a successful request to a shared server (name based virtual hosts) then it would need to include the Host header?
Well, that's unnerving.
If I type in http://www.example.com the page displays as https://www.example.com
But it then still displays the "Moved permanently" message rather than the web page content.
Maybe the Host-header-less requests simply never reach my site logs in the first place
On a shared host, this is most probable.I got brave and tried requesting a raw IP address belonging to my host. They have an error screen saying "can't find the site" with a cute little graphic, probably intended for exactly this situation. With Live Headers enabled, I could see that the browser sends all the usual headers--but, of course, no Host: header, since I didn't specify one. No numerical response code for the page itself, just for the picture.
[edited by: phranque at 9:47 pm (utc) on Sep 9, 2017]
[edit reason] Unlinked URLs for clarity [/edit]
if you asked for the http version and a 301 redirect came into play, the code I had set up in my htaccess meant that the browser was continually asking my server for an https version and my web server was continually saying "Nope, no can do" and the browser was saying "But I NEED it" and my server was saying "tough luck."Wow. A masterful summary. I am in envy of your prose.
am I right not to be concerned?A properly coded canonicalization redirect will achieve everything in one step. Sometimes, as you've found, it's impossible. The same applies to any redirect: where possible, do it in one step. If it honestly isn't possible, don't sweat it.
I had set up my SSL via Cloudflare's "flexible" option ...
why would you expect the same redirect loop when typing https://www.example.com directly into the browser?
[edited by: phranque at 9:40 pm (utc) on Sep 9, 2017]
[edit reason] Unlinked URL for clarity [/edit]
does that mean that when I typed in https://www.example.com, the code I'd put into htaccess would STILL have asked for a redirect to an https version, is that what you're saying?
No, ...
....an SSL certificate is not actually present on my own web server. So this means:
"There is an encrypted connection between your site visitors and CloudFlare, but not from CloudFlare to your server. The HTTPS condition from the htaccess or PHP will always return as off, as server is still using the http protocol."