【问题标题】:IIS Rewrite / Redirect Rules QueryIIS 重写/重定向规则查询
【发布时间】:2019-10-29 01:27:58
【问题描述】:

以下规则执行以下操作: - http://www.example.com -> https://example.com ETC -https://example.com/contacts.html->。 https://example.com/contacts 所以(所有对 HTTPS 的请求,以及所有 www ->(非)www)+ 隐藏 .HTML 扩展名。

我想添加删除以下问题的功能:

https://example.com/Home.html -> https://example.com/Home

但对于 /Home 的具体情况,我更希望它显示 /

任何帮助将不胜感激..

规则如下:

            <rewrite>
            <rules>
                <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
                </rule>
                <rule name="Redirect .html extension" stopProcessing="false">
                    <match url="^(.*)\.html$" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{URL}" pattern="(.*)\.html$" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="{R:1}" redirectType="Permanent" />
                </rule>
                <rule name="hide .html extension" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="true" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
                    </conditions>
                    <action type="Rewrite" url="{R:0}.html" />
                </rule>
            </rules>
        </rewrite>

【问题讨论】:

    标签: redirect iis


    【解决方案1】:

    我对您的规则进行了一些更改,以防止重写 /Home 和 /。然后创建了两个规则来处理对 /Home.html 的请求。

    对我来说效果很好,应该可以满足您的要求。

        <rewrite>
            <rules>
                  <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
                </rule>
                <rule name="Redirect .html extension" enabled="true" stopProcessing="true">
                    <match url="^(.*)\.html$" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="(.*)\.html$" ignoreCase="false" />
                        <add input="{URL}" pattern="^/Home.html$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{R:1}" redirectType="Permanent" />
                </rule>
                <rule name="hide .html extension" enabled="true" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="true" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
                        <add input="{URL}" pattern="^/$" negate="true" />
                        <add input="{URL}" pattern="^/Home$" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="{R:0}.html" />
                </rule>
                <rule name="redirect /Home" enabled="true" stopProcessing="true">
                    <match url="^Home.html$" />
                    <action type="Redirect" url="/" />
                </rule>
                <rule name="rewrite Home" stopProcessing="true">
                    <match url="^$" />
                    <action type="Rewrite" url="/Home.html" />
                </rule>
            </rules>
        </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-09
      • 2018-08-25
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      • 2019-10-05
      • 2013-05-11
      • 1970-01-01
      相关资源
      最近更新 更多