【问题标题】:Redirecting to HTTPS in web. Config在 Web 中重定向到 HTTPS。配置
【发布时间】:2022-02-04 23:10:19
【问题描述】:

我在 web.Config 文件中添加了一条新规则以重定向到 HTTPS。它在本地主机中工作,但是一旦我将它部署到开发环境,重定向就不起作用了。我怎样才能让它工作?

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

【问题讨论】:

    标签: c# http redirect https https-redirect


    【解决方案1】:

    使用此更新版本:

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

    【讨论】:

    • 我试过不工作
    • 此代码来自我们的生产服务器,您可以看到我的答案与提供的另一个相似。我认为您的问题出在另一个领域...
    【解决方案2】:

    在我的解决方案中,我使用了这个配置并且它有效:

    <rule name="HTTP to HTTPS redirect for all requests" stopProcessing="true">
              <match url="(.*)" />
              <conditions>
                    <add input="{HTTPS}" pattern="off" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
    

    我希望它是你的解决方案!

    【讨论】:

    • 试过这个也没用
    • 那么您可能还有另一个问题...您可以访问服务器上的 web.config 吗?
    猜你喜欢
    • 2018-03-14
    • 2019-11-15
    • 2021-07-12
    • 2013-10-11
    • 2015-02-27
    • 1970-01-01
    • 2013-08-09
    • 2020-05-28
    • 2018-11-09
    相关资源
    最近更新 更多