【问题标题】:How to redirect from http to https at Masterhost shared hosting如何在 Masterhost 共享主机上从 http 重定向到 https
【发布时间】:2018-09-20 11:03:07
【问题描述】:

如何从 http 重定向到 https 用于 linux 和 windows 用于 Masterhost 共享主机。

对于特定情况,检查连接是否安全失败,以及检查 X-Forwarded-Proto。

【问题讨论】:

    标签: asp.net .net .htaccess redirect https


    【解决方案1】:

    .htaccess

      RewriteCond %{HTTP:X-Forwarded-Port} !443
      RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    

    global.asax:

        if (Request.Headers["X-Forwarded-Port"] == "443") //masterhost hosting only
        { 
            //nothing, its secure
    
        }
        else
        {
            //force https
            if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
                Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);            
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-13
      • 2019-08-23
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 2021-03-19
      • 2018-02-19
      • 2021-09-12
      相关资源
      最近更新 更多