簡體   English   中英

用https重寫網址

[英]Url rewriting with https

我有以下網址

http://www.mywebsite.com/home

https://www.mywebsite.com/secure/reports/

當用戶輸入上述網址時,我們會加載

http://www.mywebsite.com/home.aspx

https://www.mywebsite.com/secure/reports.aspx

問題是,如果用戶輸入https://www.mywebsite.com/home ,則需要重定向到http://www.mywebsite.com/home 只需將更改https更改為http即可,因為它不安全

同樣,如果用戶輸入http://www.mywebsite.com/secure/reports ,我們需要重新加密以保護https://www.mywebsite.com/secure/reports

看到這個

protected void Application_BeginRequest(Object sender, EventArgs e)
{
   if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
   {
    Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
+   HttpContext.Current.Request.RawUrl);
   }
}

更改您的Web.Config

<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions><add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>

更多參考:Check- http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM