bri*_*nch 5 c# asp.net iis https web-config
我想使用web.config将我的asp.net网站上的所有请求重定向到带有非www的https://。那是:
http://
http://www
https://www
Run Code Online (Sandbox Code Playgroud)
应该都去
https://
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的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>
Run Code Online (Sandbox Code Playgroud)
上面的代码片段负责重定向这两个代码:
http://
http://www
Run Code Online (Sandbox Code Playgroud)
但是我错过了最后一个,那就是:
https://www ---> https://
Run Code Online (Sandbox Code Playgroud)
怎么做?
您需要添加第二条规则:
<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>
Run Code Online (Sandbox Code Playgroud)
您只需要用sitename.com您的域名替换