【问题标题】:IIS Rewrite conditions rule is not workingIIS 重写条件规则不起作用
【发布时间】:2021-03-26 12:13:50
【问题描述】:

首先谢谢大家,英语不是我的母语 但是这个问题对我来说很难

我需要 http://xxxx.show.bis.tw/event_register/index.php?id=image01http://xxxx.show.bis.tw/event_register/image01

如果用户在地址栏输入http://xxxx.show.bis.tw/event_register/image01 该网站可以运行

我认为规则是 用户可以输入那些 http://xxxx.show.bis.tw/event_register/image01 http://xxxx.show.bis.tw/event_register/index.php?id=image01

1。 http://xxxx.show.bis.tw/event_register/index.php?id=image01 像这样重定向http://xxxx.show.bis.tw/event_register/image01 并转到 rule2 重写<action type="Rewrite" url="index.php?id={C:1}" />

2。 http://xxxx.show.bis.tw/event_register/image01 只是重写<action type="Rewrite" url="index.php?id={C:1}" />

我的代码是 如果文件和目录做重定向或重写网站会损坏(css/js/image)

我尝试将 rule>1 和 rule>2 写入一个规则,但它不起作用 不知道怎么解决

    <rewrite>
        <rules>
            // 1
            <rule name="025" stopProcessing="true">
                 <match url=".*" />
                 <conditions>    // file and directory not Redirect|Rewrite
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Redirect" url="{C:0}" appendQueryString="false" />
            </rule>
            // 2
            <rule name="026">
                <match url="index\.php(.*)" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="id=(.*)" />
                </conditions>
                <action type="Redirect" url="{C:1}" appendQueryString="false" />
            </rule>
            // 3
            <rule name="027" enabled="true" stopProcessing="true">
                <match url=".*" ignoreCase="true" />
                <conditions>
                    <add input="{URL}" pattern="/index.php?id=" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php?id={R:1}" />
            </rule>
        </rules>
    </rewrite>

谢谢大家非常感谢 我几乎两天睡不着就解决这个问题

【问题讨论】:

标签: url iis mod-rewrite


【解决方案1】:

您是否尝试过在 web.config 文件中使用 rewritemaps 而不是规则?

<configuration>
<system.webServer>
<rewrite>
    <rewriteMaps>
        <rewriteMap name="rewrites">
            <add key="/event_register/image01" value="/event_register/index.php?id=image01" />            
        </rewriteMap>
    </rewriteMaps>
</rewrite>
</system.webServer>
</configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-12
    • 1970-01-01
    • 2015-07-10
    • 2017-03-08
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    相关资源
    最近更新 更多