Redirect issue - too many


Had a few redirect issues on my site the last few days - too many redirects. The site is very basic install and no plugin redirects, just a slice of code in the htaccess file. I tried clearing browser/cache/Varnish, etc, but still no joy.

Contacted support and received this reply:

your primary domain is already set for www which means it will redirect it already but the rules try to enforce double redirection towards www which is highly possible reason of causing redirect error.<<

Hmm… not buying that? Primary Domain is set to /www. in control panel, but don’t see how that is a problem. Would be the same problem if I set / ?

I use the same code on three other hosts with no problem. Is the code below compatible with CW?

# BEGIN Redirect http to https and non-www to www in one rule TOP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*){REQUEST_URI} [L,R=301]

Thank you.

Edit for code layout

Yea, you got a total clunker of a support rep on that one - what you have set as primary domain has nothing to do with this issue.

Because Cloudways runs a proxy configuration for Apache/Nginx, the redirect code in the htaccess file needs to be a bit different from traditional Apache-only setups.

Switch to this

# Force HTTPS + www in one step
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^ [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$$1 [R=301,L]

and you should be good to go.

Note though - if you’re setting this in htaccess, you must not use the HTTPS redirect setting that’s in the Cloudways App dashboard!


Hi Paul,

Thank you, your code works great.

A total clunker for sure :slight_smile: