Редирект с HTTP на HTTPS в htaccess

Как настроить перенаправление с HTTP на HTTPS в PHP и .htaccess на разных хостингах.

Редирект в PHP


if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off") {
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
exit;
}

Timeweb

SetEnvIf X-HTTPS 1 HTTPS

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-HTTPS} !1
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Masterhost

RewriteCond %{HTTP:PORT} !443
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

reg.ru
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

beget.com
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Sprinthost.ru
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

jino.ru
RewriteCond %{HTTP:X-Forwarded-Protocol} !=https
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]


  27.01.24 / 12:05 | htaccess |   207 | 0   0