【问题标题】:Site not redirecting from www to https网站未从 www 重定向到 https
【发布时间】:2021-04-02 00:30:57
【问题描述】:

在 IIS7 上,我的网站没有从 www.example.com 重定向到 https://example.com

而是尝试打开https://www.example.com

这是 web.config 文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
        <rules>
                <clear />
                <rule name="WWW to HTTPS"> 
                    <match url="(.*)" /> 
                    <conditions> 
                        <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" /> 
                    </conditions> 
                    <action type="Redirect" url="https://example.com/{R:1}" /> 
                </rule> 

                <rule name="HTTP TO HTTPS" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
                </rule>

                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="backend-api/(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{URL}" pattern="^/(backend-api)/.*" />
                    </conditions>
                    <action type="Rewrite" url="http://localhost:3033/{R:1}" />
                </rule>

                <rule name="AngularPageRefresh" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
        </rules>
        <outboundRules>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
  </system.webServer>
</configuration>

我错过了什么?

【问题讨论】:

标签: web iis https


【解决方案1】:

您可以使用以下规则:

<rule name="test1" stopProcessing="true">
   <match url="^(.*)$" />
      <conditions>
         <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
      </conditions>
   <action type="Redirect" url="https://{C:1}" />
</rule>

【讨论】:

  • 我将此添加为第一条规则,但仍然看到此错误。重新启动服务器但结果相同:(
  • 你遇到了什么错误?您是否禁用了其他规则?然后清除浏览器的缓存并重试。或者您可以使用failed request tracking 获取更详细的错误信息。
猜你喜欢
  • 1970-01-01
  • 2020-05-22
  • 1970-01-01
  • 1970-01-01
  • 2019-10-05
  • 1970-01-01
  • 2019-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多