【问题标题】:How to fix redirection from https//www to https//non-www version of website?如何修复从 https//www 到 https//non-www 版本的网站的重定向?
【发布时间】:2019-10-05 21:33:18
【问题描述】:

上周我在 iis 中添加了 ssl,并在我的网站的 web.config 中配置了重定向 301 规则。

今天我注意到https://www 版本没有重定向到我网站的https://non-www 版本,并且图片和css 文件等资源在我的网站的两个版本中都可用。

我添加到 web.config 中的这些规则是否正确?

由于 IIS 和 wordpress,我不得不将资源重定向和 Unicode Url 添加到 web.config。

从 http 到 https 的重定向工作正常

从 http//www 重定向到 http://non-www 正在工作

但是从 https//www 重定向到 https://non-www 不起作用!

我的 web.config 文件:

<rewrite>
<rules>
<rule name="HTTPS" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" 
redirectType="Permanent" />
</rule>
<rule name="Redirect Image to HTTP" stopProcessing="true">
<match url=".*\.(gif|jpg|jpeg|png|css|js|pdf|ttf|woff2|woff|mp4)$" 
ignoreCase="true" />
<action type="Rewrite" url="{R:0}" />
</rule>
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
<serverVariables>
<set name="REQUEST_URI" value="{UNENCODED_URL}" replace="true" />
</serverVariables>
</rule>
</rules>

【问题讨论】:

    标签: iis https url-redirection


    【解决方案1】:

    根据您的描述,您的规则似乎没有问题,那么您似乎想意识到将任何 https 请求(如https://www.example.com)更改为https://example.com 对吧?我在这里做了一个样本。这是规则,希望对您有所帮助。

     <rule name="rule1" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^on$" />
                        <add input="{HTTP_HOST}" pattern="www[.](.+)" />
                    </conditions>
                    <action type="Redirect" url="https://{C:1}/{R:0}" />
                </rule>
    

    【讨论】:

      猜你喜欢
      • 2012-06-09
      • 1970-01-01
      • 2019-10-26
      • 2018-07-03
      • 2020-05-22
      • 1970-01-01
      • 2013-09-03
      • 2020-10-01
      相关资源
      最近更新 更多