Redirect NON-www to www for https

11,013

Solution 1

You can use the following :

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

This will redirect

to

Solution 2

I'm using this on a Joomla site and it redirects everything to https://www I can't see this solution anywhere else so thought I'd share it

RewriteCond %{HTTP_HOST} ^domainname\.co.uk [NC]
RewriteRule ^(.*)$ https://www.domainname.co.uk/$1 [R=301,L]
Share:
11,013
Overnet
Author by

Overnet

Updated on June 04, 2022

Comments

  • Overnet
    Overnet almost 2 years

    I've the following redirect

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

    How can I redirect non WWW https to WWW?

    The htaccess is located in the public_html folder