我最近將我的asp.net MVC網站切換到https,並希望所有現有通信都使用web重定向到https://www.example.com .config重寫。Web.config重寫http + www和http非www和https非www轉到https:// www
我嘗試了各種組合,但尚未成功。 需要處理以下三種情形:
http:// http://www https://
我最近將我的asp.net MVC網站切換到https,並希望所有現有通信都使用web重定向到https://www.example.com .config重寫。Web.config重寫http + www和http非www和https非www轉到https:// www
我嘗試了各種組合,但尚未成功。 需要處理以下三種情形:
http:// http://www https://
試試這個它可以幫助你:
<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>
感謝Praveen,但這不關心www我猜 – geekonweb
您可將您的流量使用Global.asax
以及使用https。
方法名稱:Application_BeginRequest
您的代碼重新定向將是這個樣子
strProtocol = "https";
if (HttpContext.Current.Request.Url.ToString().ToLower().StartsWith("http:") == true)
{
Response.Redirect(strProtocol + "://" + strYourHostName + strYourRemainingURL, false);
}
你可以保持在web.config中的協議和主機名,並從那裏挑選。
https://stackoverflow.com/questions/17714732/web-config-redirect-non-www-to-www/17715586#17715586可能有幫助 – Satpal