I've been given several requests to rewrite a URL in IIS. One of them includes having the .html page as part of the URL, but without the HTML tag. For example, www.foo.com/bar.html would be displayed as www.foo.com/bar instead. I have this rule to accomplish that and it seems to work ok.
<rule name="Hide .html ext" enabled="true">
<match url="^(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<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>
The problem I'm having is that since index.html is a default document in IIS, so www.foo.com never shows index.html for my html rewrite rule to handle it (at least that is my assumption as to what is happening). This is the same if the page is something like www.foo.com/bar/index.html. They would want www.foo.com/bar to redirect to www.foo.com/bar/index in the URL.
Essentially is it possible to somehow force the default document to show? I've been attempting all sorts of strange scenarios using {PATH_INFO}, {URL}, and {PATH_TRANSLATED} to somehow attempt to catch any index.html page to rewrite it "correctly" in the URL.
Example attempt that I know is in the wrong direction:
<rule name="Include /index" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{PATH_INFO}" pattern="(.+?(?=(index.html|/index.html|/index.html/)$)|^(index.html))" />
<add input="{URL}" pattern="(.+?(?=(index|/index|/index/)$)|^((index)|(/index/)))" negate="true" />
</conditions>
<action type="Redirect" url="/index" appendQueryString="false" redirectType="Permanent" />
</rule>
I feel like I'm overthinking this and there's possibly a simpler solution that uses IIS URL rewrite.
question from:
https://stackoverflow.com/questions/65852830/show-default-document-extension-in-url 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…