2016-12-07 140 views

回答

0

從上面的代碼應該工作。一切都很好:)

你必須確保mod_rewritephp.ini
激活
如果您在Linux上,你可以用a2enmod rewrite
激活它,然後嘗試這樣的東西,並把它放在你的.htaccess頂部文件

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 

或PHP,你可以迫使它這樣的:

// Force HTTPS for security 
if($_SERVER["HTTPS"] != "on") { 
$pageURL = "Location: https://"; 
if ($_SERVER["SERVER_PORT"] != "80") { 
    $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; 
} else { 
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; 
} 
header($pageURL); 
} 
相關問題