iis url 重写删除 .html 导致 404 Not Found

问题描述 投票:0回答:1

我想要

http://www.example.com/pages/service.html
->
http://www.example.com/pages/service

但结果是 404 not Found

请帮助我...

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite" stopProcessing="false">
                    <match url="^pages/(.*).html" />
                    <action type="Rewrite" url="/pages/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
html iis url-rewriting
1个回答
0
投票

你可以尝试这个规则:

<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>

https://stackoverflow.com/a/35523747/13336642

© www.soinside.com 2019 - 2024. All rights reserved.