Hey there,
I have a problem with my http/https www/non-www redirects. I’m not going to pretend to fully understand all this, but I had no problems when I was on my old server (and also not with Cloudflare yet).
Basically, this is what I have:
DNS:
Two A records, pointing to Cloudflare servers
One CNAME record for www pointing to example.com
SSL:
Flexible by Cloudflare
SERVER:
There is a https force redirect enabled, because that is currently the best way for me to achieve at least that (although my goal is to achieve this off-server)
HTACCESS:
# Turn on RewriteEngine
RewriteEngine on
# Force trailing slash
RewriteCond %{REQUEST_URI} !/(.+)/$
RewriteCond %{REQUEST_URI} !/(go/.+)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ https://example.com/$1/ [R=301,L]
# Force HTTPS and WWW
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [OR,NC]
#RewriteCond %{HTTP:X-Forwarded-Proto} !https
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
The first htaccess block is to make sure all urls have a trailing slash, except filetypes and affiliate links in the form of /go*
.
The second block is a leftover from my previous website that did the trick and isn’t working anymore for some reason. It took care of https and non-www urls, which was and stil is my preferred way to go. Back then, I had no extra settings on the server.
My ultimate goal is to be able to redirect all appropriate urls to https and non-www in one step (to avoid two or even three redirects - because why waste time).
However, if I use a www url now (wither with http or https) I get redirect cycling.
If I don’t use www and use http, I first get a 301 redirect to https and then another 301 redirect to a trailing slash in case the original url didn’t have one.
Any ideas as to what I’m missing?