2016-12-07 142 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); 
} 
相关问题