回文章列表
作者style520.bbs@ptt.cc (XXYY), 信區: 386bsd
標題[問題] 利用 .htaccess 來達到 ForceSSL
時間批踢踢實業 (Fri Dec 8 14:00:51 2006)
轉信站: GIBBS!ccnews.ncku!news2!Spring!ctu-peer!ctu-reader!news.nctu!ptt
Origin: sally.csie.ntu.edu.tw


在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那樣的功能嗎?




--
※ 發信站: 批踢踢實業坊(ptt.cc) 
◆ From: 210.60.29.70
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻