How to redirect HTTP to HTTPS Using .htaccess

You are here:
Estimated reading time: < 1 min

Redirect All Web Traffic

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP:CF-Visitor} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Redirect Only Specified Domain

RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Note: Replace “example\.com” with your actual domain name, Don’t forget to add “\” before dot!

Redirect Specified Folder

RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Note: Replace “folder” with your actual folder name!

Was this article helpful?
Dislike 0
Views: 37