Reputation: 55
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
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]
Upvotes: 2
Views: 399
Reputation: 41219
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]
Upvotes: 1