2017-06-28 69 views
0

我想使用web.config將我的asp.net網站上的所有請求重定向到https://與非www。那就是:如何通過web.config將http重定向到https和www到非www?

http:// 
http://www 
https://www 

都應該去

https:// 

到目前爲止,我有這對我的web.config:

<system.webServer> 
... 
<rewrite> 
    <rules> 
    <clear /> 
    <rule name="Redirect to https" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /> 
    </rule> 
    </rules> 
</rewrite> 
</system.webServer> 

上面的代碼需要重新引導這兩種護理:

http:// 
http://www 

但我失蹤日e最後,這是:

https://www ---> https:// 

如何做到這一點?

回答

2

您需要添加第二條規則:

<rule name="NonWwwRedirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
     <add input="{HTTP_HOST}" pattern="^www.sitename\.com$" /> 
    </conditions> 
    <action type="Redirect" url="http://sitename.com/{R:1}" /> 
</rule> 

你只需要使用您的域名來代替sitename.com

相關問題