htaccess force redirect to https code example
Example 1: force http to https htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https:
Example 2: force .htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https:
Example 3: htaccess redirect to https
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^yourdomain\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com
RewriteRule .* https:
Example 4: redirect to http to https .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https:
</IfModule>
Example 5: .htaccess redirect to https
<IfModule mod_rewrite.c>
....
....
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https:
...
...
</IfModule>
Example 6: http redirect to https htaccess
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https: