利用 .htaccess 來達到 ForceSSL - BBS

Table of Contents


在PHP裡,可以使用以下方法來達到強制使用SSL連線

<?php
if (!isset($_SERVER["HTTPS"]) || $_SERVER["HTTPS"]!='on')
{
$ssl_url = 'https://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
header("Location: $ssl_url");
exit;
}


在 .htaccess 裡,我想到一個方法

Redirect / https://www.mydomain.com/


但問題在於
Redirect Syntax: Redirect [status] URL-path URL
URL 必須為絕對網址, 若果 Apache 的 ServerName 有改, .htaccess 也要跟著改

有什麼方法達到像PHP那樣的功能嗎?




--

All Comments