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

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

Редирект в PHP

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

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

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

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

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

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

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


  27.01.24 / 15:05 | htaccess |   71 | 0   0