how to auto redirect http to https code example
Example 1: 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 2: redirect htaccess http to https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https:
Example 3: how to automatically redirect to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https:
Example 4: redirect https
if ($_SERVER['HTTPS'] != "on")
{
$url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("Location: $url");
exit;
}