ASP:
以https开始,请在该ASP页面顶部添加如下代码:
Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "off") Then
Dim xredir__, xqstr__
xredir__ = "https://" & Request.ServerVariables("SERVER_NAME") & _
Request.ServerVariables("SCRIPT_NAME")
xqstr__ = Request.ServerVariables("QUERY_STRING")
if xqstr__ <> "" Then xredir__ = xredir__ & "?" & xqstr__
Response.redirect xredir__
End if
%>
相反的,强迫以Http开始
Response.Buffer = True
If (Request.ServerVariables("HTTPS") = "on") Then
Dim xredir__, xqstr__
xredir__ = "http://" & Request.ServerVariables("SERVER_NAME") & _
Request.ServerVariables("SCRIPT_NAME")
xqstr__ = Request.ServerVariables("QUERY_STRING")
if xqstr__ <> "" Then xredir__ = xredir__ & "?" & xqstr__
Response.redirect xredir__
End if
%>
php:
如果网页使用https访问,在网页开头加入以下代码:
//http转化为https
if($_SERVER["HTTPS"]<>"on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?>
如果网页使用http访问,在网页开头加入以下代码:
//https转化为http
if($_SERVER["HTTPS"]=="on")
{
$xredir="http://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?>