• http重定向到https


    本教程主要是对 网站http重定向到https,其中包括目前市面上常用各种服务器环境(Apache,Ngnix,IIS7系列)设置方法。

    第一“IIS7” 环境中的设置方法
    1.下载安装IIS的URL重写模块:Microsoft URL Rewrite Module

    2.安装完毕 在Internet服务中找到SSL设置
    操作 ------》取消勾选“SSL设置”中的“要求 SSL”

    3. 选择要配置的网站,点击之后,找到“URL重写

    4.进入“URL重写”模块,点击“添加规则”

    5.选择“空白规则”

    名称:HTTP to HTTPS redirect

    模式:(.*)

    6. 条件输入:{HTTPS} 模式:off 或 ^OFF$

    7.重定向URL:https://{HTTP_HOST}/{R:1}

    重定向类型:已找到(302) 或 参阅其它(303)

    8**.配置完成后“应用”到当前站点**

    第二“Apache” 环境中的设置方法
    1.先打开url重定向支持
    @1打开Apache/conf/httpd.conf,找到 #LoadModule rewrite_module modules/mod_rewrite.so 去掉#号
    @2找到你网站目录的段,比如我的网站目录是c:/www,找到
    <Directory “C:/www”>

    修改其中的 AllowOverride None 为 AllowOverride All3)重启apache服务
    2.设置重定向规则
    @1在你网站目录下放一个.htaccess文件。windows环境下,不能把文件直接改名为.htaccess,会提示你必须输入文件名。所以我们先新建一个“新建文本文档.txt”文档,记事本打开,选择另存为,保存类型选择“所有文件(.)”,文件名输入“.htaccess”,保存。这样便生成了一个.htaccess文件。

    @2编辑器打开.htaccess文件(网站根目录下的文件),写入如下规则:
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteCond %{REQUEST_URI} !^/tz.php
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]

    总体来说上面规则的意思是:
    如果访问的url的端口不是443,且访问页面不是tz.php,则应用RewriteRule这条规则。这样便实现了:访问了 http://localhost/index.php 或者 http://localhost/admin/index.php 等页面的时候会自动跳转到 https://localhost/index.php 或者 https://localhost/admin/index.php,但是访问 http://localhost/tz.php 的时候就不会做任何跳转,也就是说 http://localhost/tz.php 和 https://localhost/tz.php 两个地址都可以访问

    第三 “Ngnix ” 环境中的设置方法

    2.现在nginx新版本已经换了种写法。
    下面是nginx http页面重定向到https页面最新支持的写法:

    server {
    listen 80;
    server_name my.domain.com;
    return 301 https://$server_name$request_uri;
    }
    server {
    listen 443 ssl;
    server_name my.domain.com;
    rewrite ^/ http://www.xxxxx.com/;
    }
    ————————————————
    本文摘自:https://blog.csdn.net/jackbon8/article/details/84578904

  • 相关阅读:
    Rewrite the master page form action attribute in asp.net 2.0
    Using Output Cache
    An invalid character was found in text content!
    Microsoft Football Scoreboard
    A typical ASP.NET 2.0 Configuration Settings
    Visual Studio 2005 Web Application Projects Released!
    Test Driven Development with Visual Studio 2005 Team System
    How to pass a parameter to HyperLink in GridView/DataList
    MS的一个BUG折腾我几个小时!
    Create builtin tables in your own database to handle exceptions, Part 2
  • 原文地址:https://www.cnblogs.com/Shaina/p/15149305.html
Copyright © 2020-2023  润新知