1

So far I have .htaccess file which is able to redirect correctly from (domain.com) to (https://www.domain.com) but not working if I go to www.domain.com and it must redirect (www.domain.com) to (https://www.domain.com)

I need (https://www) always before my site url

my .htaccess file

RewriteEngine On 

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

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

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Possible duplicate of [htaccess redirect to https://www](http://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www) – shrmn Apr 02 '16 at 09:02

1 Answers1

0

Replace your first 2 redirect rules with this rule:

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

Make sure to clear your browser cache before testing this.

anubhava
  • 761,203
  • 64
  • 569
  • 643