Domanda


Voglio aprire la pagina di accesso del mio sito Web con https Solo, non il sito web di Comeplete. Dopo l'autenicazione del login (successo), il sito Web è di nuovo in esecuzione http.

Attualmente la mia pagina di accesso principale è test_index.php dove ho incluso test_header.php

Il mio codice di base su test_header.php è

if($_SERVER['SERVER_PORT'] != 443) {
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
   exit();
}

Ma questo rende il sito Web completo in https
Ho anche letto qui che può essere possibile tramite .htaccess, quindi rimuovo lo snippet di codice sopra da test_header.php e aggiungere le seguenti righe in .htaccess file e

<IfModule mod_rewrite.c>
  RewriteEngine on
  # 301 redirect to domain to 'www.'
  RewriteCond %{HTTP_HOST} ^testweb.com$ [NC]
  RewriteRule ^(.*)$ http://www.testweb.com/$1 [R=301,L]
</IfModule>

<FilesMatch test_index.php>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
</FilesMatch>

Nota: Testweb.com è solo un nome immaginario, non un vero sito web

Ma ancora il sito Web completo eseguito su HTTPS, per favore dimmi dove sto facendo errore ??

Modificare

@WebBiedave per favore controlla il mio Codice aggiornato , è il modo giusto ??

if ($_SERVER['REQUEST_URI'] == '/test_index.php') { // only check https on login
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        header("HTTP/1.1 301 Moved Permanently");
        header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
        exit();
    } else {
        die("Sorry,Your website is not secure");        
    }
} elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        // header("HTTP/1.1 301 Moved Permanently");
        header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
        exit();
}

Grazie

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top