Force users to non-www and https version of site

I want to redirect all visitors to use https and the non-www. version of my site. I have tried using the following directives which I got from Bootstrap but I get a message telling me there are too many redirects.

# force https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# force non-www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ %{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]

I’ve also tried the following with the same result:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule .? http://domain.com%{REQUEST_URI} [R=301,L]

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://domain.com/$1 [L,R]

This is what I’m aiming for:

https://www.domain.com
https://domain.com <=== all redirect to

Try this:

https://www.siteground.com/kb/how-to-force-ssl-with-


Or this https://really-simple-ssl.com/knowledge-base/manually-insert-htaccess-redirect-http-to-https/
1 Like

There seem to be so many ways to do this! Anyways, my problem seemed to be because the domain is using Cloudflare. I’ve been able to change a setting there to force it through https.

With CloudFlare try:

  1. Overview → Quick Actions → Devemopment Mode (prevents caching)
  2. Cacning → Purge Individual Files → Purge Everything (what it says on the tin :slight_smile:

Edit:
Both are available on the FREE version

1 Like

Yes, I had to set the SSL setting to flexible, rather than full - which is puzzling - and set up a page rule.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.