How to redirect HTTP to HTTPS using .htaccess

How to redirect HTTP to HTTPS using .htaccess

Create a .htaccess file with content in frame bellow and upload it to server. This will redirect URLs without http to URLs with https.

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP:Host} (.*) 
RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} (.*) 
RewriteRule .? https://%1%2 [R=301,L]

Applies To

IIS, Web server, Web site, URL Rewriter, .htaccess

See Also