我试图使用web.config从页面中删除html扩展名.下面是我在web.config文件中使用的代码
<rewrite>
<rules>
<rule name="rewrite html">
<match url="(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).html" />
</conditions>
<action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
它工作正常并删除html扩展,但这里似乎有2个问题:
当我把'斜杠'它不起作用,并给我没有发现错误.例如:http://example.com/my-page/现在它不起作用,但我放了http://example.com/my-page它会工作正常,所以我希望他们两个都能工作
其他问题是.html页面仍在打开.例如,如果我打开页面,因为http://example.com/my-page.html它也在工作,但我希望它http://example.com/my-page自动转换,我知道我可以使用301重定向,但这不会起作用,因为这里有很多文件,所以我必须使用不同的不同网址的301规则.
请指教.
谢谢