Redirecting non-www to www https


I am trying to redirect a non-www version of my website to

The website is a Wordpress website and is currently set to in my WP-admin

If I type, it redirects to, but I would like all versions including and excluding www. to go to

I’ve tried the following but not having any luck.

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*){REQUEST_URI} [L,R=301]

Can anyone help me with the redirect?


1 Like

Hi there toolman,

my htaccess file with your url would look like this…

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

RewriteCond %{HTTPS} !^on$
RewriteRule (.*)$1 [R,L]

Perhaps that will also work for you. :winky:


1 Like


Many thanks. I’ve tried that and I’m getting this error:

"The page isn’t redirecting properly

An error occurred during a connection to

This problem can sometimes be caused by disabling or refusing to accept cookies."

Do you have any suggestions to why this is? Could it be because in my WordPress admin I have the site URL as

Hi there toolman,

I do not know what problems Wordpress could cause. :unhappy:

What I can say, though, is that when I tried this link…

…it took me smoothly to…

Is it possible that you are experiencing a cache problem ?



Thanks for the reply.

Ok, I’ve cleared my cache and I can see it forwarding to

I guess it must be a setting in WordPress. I will see if I can see anything in there.

Thanks for your help!

Hi there toolman,

as a matter of interest, I use these three add-ons/extensions…

"uBlock Origin " , "Ghostery " and "I don’t care about cookies "

…without any problems. :winky:

Also note that…

…will work OK.


1 Like

Thanks for the tips, I will check them out :slight_smile:

If you want peeps to go to the www version then you need to change to that in WP admin.

Thanks for the reply.

I’ve changed the site URL so use www.

Do I need to change the WordPress URL in there too? I think on another site when I changed that part, it broke the website.


Hi, you should add the below code:

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

Also, you should change the Site URL, WordPress Address URL to www version to get it work smoothly. I use to add this code on all my sites and to the site that I create newly.

1 Like

Thanks everyone for the replies.

This is what I used in the end:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^website\ [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$$1 [R,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]

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