有没有一种干净利落的方法可以将所有访问HTTP://版本的站点的尝试重定向到它的HTTPS://等效项?
发布于 2011-09-30 10:12:44
我认为最干净的方式是所描述的here on IIS-aid.com。它只适用于web.config,所以如果你改变了服务器,你不必记住你使用403.4自定义错误页面或其他特殊权限所经历的所有步骤,它就能正常工作。
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
发布于 2017-05-31 19:11:48
Global.asax
protected void Application_BeginRequest()
{
if (!Context.Request.Url.AbsoluteUri.Contains("localhost") && !Context.Request.IsSecureConnection)
Response.Redirect(Context.Request.Url.ToString().Replace("http:", "https:"));
}
发布于 2018-12-11 21:46:21
我使用经典的asp (内部网),在需要登录的页面上,logon include文件执行重定向:
if Request.ServerVariables("SERVER_PORT_SECURE") <> "1" or Request.ServerVariables("HTTPS") <> "on" then
Response.Redirect "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
end if
这当然不包括GET或POST数据。因此,实际上它是一个干净的重定向到您的安全页面。
https://stackoverflow.com/questions/46347
复制相似问题