2

I am trying to do a redirect from non-www(http) and www(http) to https://www but it does not work. Need the following to work. Please help

  1. http://example.com redirect to https://www.example.com
  2. http://www.example.com redirect to https://www.example.com

Current htaccess file

rewritecond %{http_host} ^example.com [nc]

rewriterule ^(.*)$ https://www.example.com/$1 [r=301,nc]

Tried below rule

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
  • Sorry, but this question has been asked and answered about 65836593659 times alone here on SO. Are you _really_ sure that none of all those answers help? _Why not?_ And why should the 65836593659th answer then make a difference? – arkascha Apr 17 '18 at 05:39

1 Answers1

1

You can use this :

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
RewriteRule ^.*$ https://www.example.com%{REQUEST_URI} [NE,L,R=301]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115