首页 > 解决方案 > IIS 将规则全部重写到 index.php,除了 /edit 目录

问题描述

您好,我正在尝试这样做,所以当我输入 url /edit 然后将我放入目录 /edit 中。其他一切都只在 index.php

<rules>
            <rule name="Imported Rule 1" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" pattern="(\.png|\.jpg|\.gif|\.jpeg|\.js|\.css|\.ico|\.mp4|captcha.php|servertime.php|robots.txt)$" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" appendQueryString="true" />
            </rule>
        </rules>

当前,此代码将所有内容重定向到 index.php 当我添加时:

<rule name="Imported Rule 1-1" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="Imported Rule 2" stopProcessing="true">
                <match url="^edit/?(.*)$" />
                <action type="Rewrite" url="edit/index.php" />
            </rule>
            <rule name="Imported Rule 3" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <action type="Rewrite" url="index.php" />
            </rule>

目录 /edit 打开,但我失去了另一个重定向全部到 index.php

标签: iis

解决方案


您需要一个新的“规则”,只需确保在其他规则之前添加它:)

<rule name="rule1" stopProcessing="true">
    <match url="^edit" />
    <action type="None" />
</rule>

推荐阅读