当前位置: 动力学知识库 > 问答 > 编程问答 >

iis - Rewrite .html to extensionless not working if subdirectory exists with same name

问题描述:

I have legacy site that is a series of hmtl pages, some in directories. I'm trying to add rewrite rules via IIS so that the urls work without the .html extension.

For example: www.example.com/pets/dogs.html becomes www.example.com/pets/dogs. The below works unless there is a directory as well as a .html page with same name e.g www.example.com/pets.html and www.example.com/pets/ both exist in the sites directory. How do I get around this?

<rules>

<rule name="extensionless" stopProcessing="true">

<match url="(.*)\.html$" />

<action type="Redirect" url="{R:1}" redirectType="Permanent" />

</rule>

<rule name="removeextension" enabled="true">

<match url=".*" negate="false" />

<conditions>

<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />

</conditions>

<action type="Rewrite" url="{R:0}.html" />

</rule>

</rules>

分享给朋友:
您可能感兴趣的文章:
随机阅读: