Redirect to HTTP non-www to HTTPS www with htaccess

I intended to redirect non-www to www and http to https. For that I have used below code and it’s resolving perfectly. Please check whether code is correct or not.

RewriteEngine On
RewriteBase /
#Redirect non-www to www

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

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.pnrstatusbuzz.in/ %{REQUEST_URI}

Thank You.

You Can Do It in following way:-

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

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

Thanks for the response, i will correct this as per your suggestion.

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