从 web.config 文件重定向 url 无法正常工作

redirect url from web.config file not working properly

我想删除我的 html 扩展名,但在目录中删除时失败了。 我网站的 link1 工作正常,但其他目录 link 工作不正常。 link2

我想在这个 link

末尾删除 html 扩展

http://mremind.com/products-services/credentialing.html

但在我重写之后

http://mremind.com/products-services/credentialing/ which is not working.

在 stackover 流程​​中 other question 我找到了我的问题的解决方案,但它无法正常工作。

我在 web.config 文件中的解决方案是

<rewrite>
    <rules>
        <rule name="Hide .html ext">
            <match ignoreCase="true" url="^(.*)"/>
            <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>
        <rule name="Redirecting .html ext" stopProcessing="true">
            <match url="^(.*).html"/>
            <conditions logicalGrouping="MatchAny">
                <add input="{URL}" pattern="(.*).html"/>
            </conditions>
            <action type="Redirect" url="{R:1}"/>
        </rule>
    </rules>
</rewrite>

我认为你想要的需要另一个重写规则。您从 credentialing.html 重定向到 credentialing,但该文件不存在,因此您可能收到 404。 您需要的是再次添加 .html 扩展名作为重写的规则,以便 IIS 可以再次找到该文件。

<rule name="No html ext" stopProcessing="true">
  <match url="^([a-z0-9-_/]+)$" ignoreCase="true" />
  <action type="Rewrite" url="{R:1}.html" />
</rule>