IIS 重写更改文件名

IIS rewrite change filename

我在论坛应用程序中有一些旧 URL 指向 http://mydomain.tld/showthread.php?p=xxxx,其中 xxxx 是整数 ID。

我的新论坛应用程序使用 viewtopic.php?p=xxxx,我想使用 IIS web.config 重写规则来处理这个问题。

我尝试添加最后一条规则如下:

<rewrite>
            <rules>
                <rule name="Redirect www to non www" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Redirect" url="http://domain.tld/{R:1}" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^domain\.tld" negate="true" />
                    </conditions>
                </rule>

                <!-- this for change from showthread.php to viewtopic.php -->
                <rule name="Rewrite" stopProcessing="true">
                    <match url="(.*)showthread\.php" />
                    <action type="Rewrite" url="viewtopic\.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>

但是,它无法重定向到 viewtopic.php。有什么建议吗?

我必须在 IIS 中 enable httpRedirect。然后我在论坛根目录的 web.config 中使用了这个重定向规则:

<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
         <add wildcard="*showthread.php" destination="/viewtopic.php?$P" />
</httpRedirect>