【问题标题】:web.config - 2nd URL rewrite rule not wokingweb.config - 第二个 URL 重写规则不起作用
【发布时间】:2020-04-24 17:53:28
【问题描述】:

我的 wordpress 有 2 条 URL 重写规则,这是第 1 条规则:

<rule name="wordpress" patternSyntax="Wildcard">
    <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"/>
</rule>

这是第二条规则:

<rule name="Redirect to https" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

它们都独立工作。但是,如果我将两个规则结合起来,如下所示:

<rewrite>
    <rules>
        <rule name="wordpress" patternSyntax="Wildcard">
            <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"/>
        </rule>

        <rule name="Redirect to https" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>

只有第一条规则有效,第二条规则被忽略,就好像它不存在一样。如何让第 2 条规则与第 1 条规则一起使用?

【问题讨论】:

标签: iis web-config


【解决方案1】:

你可以试试这个规则:

<rule name="Redirect to https" enabled="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
            </rule>
            <rule name="wordpress" enabled="true" patternSyntax="Wildcard" 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=" index.php" />
            </rule>

最好的问候,

山姆

【讨论】:

    猜你喜欢
    • 2012-08-05
    • 2011-08-15
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 2015-07-05
    • 2013-01-27
    • 2016-11-28
    • 1970-01-01
    相关资源
    最近更新 更多