不是重定向URL重写规则

问题描述 投票:0回答:2

我有我的.NET MVC的网站在液体网络云中托管。我想,如果他们进入以下网址http://example.com,http://www.example.com,https://example.com所有网站的用户重定向

https://www.example.com(即一致的URL不管他们是如何进入)我想在web.config中,但没有运气下面的代码。

    <rule name="Redirect Non WWW" stopProcessing="true" > 
    <match url="^(http\.)(.*)$" />  
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTPS}" pattern="^OFF$" />  
         <add input="{HTTP_HOST}" pattern="^https://www.example.com$" />  

          </conditions>
          <action type="Redirect" redirectType="Permanent" url="https://www.example.com/{R:0}" appendQueryString="true" />
        </rule>

域名已注册为www.example.com和SSL的站点上启用。

url-rewriting
2个回答
0
投票

您已经使用MatchAll,也可以设置该URL应该有https开始rediretion条件!只要将它改变成http代替:

不正确的:

 <add input="{HTTP_HOST}" pattern="^https://www.example.com$" /> 

正确:

 <add input="{HTTP_HOST}" pattern="^http://www.example.com$" />

0
投票

既然你要强制重定向到使用HTTPS,(*)会匹配所有URL,你可以把该模式设置关闭。

<rule name="HTTP to HTTPS Redirection" stopProcessing="true">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTPS}" pattern="off" />
        </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>

更新: 没有与方法1中的任何问题,同时也加入了这个对于那些谁稍后访问这个职位。

方法2:

<rule name="HTTP to HTTPS Redirection" enabled="true">
    <match url="(.*)" />
    <action type="Redirect" url="https://www.example.com/{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
© www.soinside.com 2019 - 2024. All rights reserved.