(PHP)实现http跳转https

Home > 代码调试 > (PHP)实现http跳转https

今天在空间里秘密放了个PHProxy,不想被关注,即便被关注也不能让看到在做什么,于是偶就想到给这个目录做始终加密连接。下面是实现方法(偶用的第一种php实现跳转到https)。
PS:而后会考虑使用IP限制访问。

PHP实现http跳转到https

在网页开头加入以下代码:

  1. <?php
  2. //http转化为https
  3. if ($_SERVER["HTTPS"]<>”on”)
  4. {
  5. $xredir=”https://”.$_SERVER["SERVER_NAME"].
  6. $_SERVER["REQUEST_URI"];
  7. header(“Location: ”.$xredir);
  8. }
  9. ?>

参考自:PHP实现http与https转化

IIS ASP实现Http跳转https

If Request.ServerVariables(“HTTPS”) = “off” Then
Response.Redirect “https://” & Request.ServerVariables(“HTTP_HOST”) & “/Exchange”
End If

可以参考这里:http://support.microsoft.com/kb/839357/en-us

.htaccess 配置重定向http跳转到https

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]

参考自:http 跳转到https的问题

也可以这样写:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

附注:以上实现http跳转https方法除asp外都经过测试成功。

关于 .htaccess 文件的更多使用技巧阅读:

允许浏览目录(目录列表)访问,让爬虫更轻松的索引网站文件
把访问其他主机名地址重定向到指定主机名(域名)
Apache开启Rewrite环境
apache配置rewrite(静态化)
学习 WordPress安全白皮书

转载原创文章请注明,转载自:[Lin's Space|Only]

本文链接: http://clin003.com/debug/how-to-redirect-an-http-connection-to-https-2018/

Google比较注重原创性和时效性,若没有找到需要的内容可尝试以下搜素。

This entry was posted in 代码调试 and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>