1

I have a MVC project with razor pages. I am moving some razor pages in static html pages but I do not like I see in url the index.html extension.

I only wrote a 301 redirect rule:

<rule name="no-index-html">
    <match url="^(.*)/index.html$" ignoreCase="false" />
    <action type="Redirect" url="{R:1}" />
</rule>

It works... almost works... It makes 2 redirects: enter image description here

The firstone is correct, the second one no..

The same happen if I write the url without the final slash.. A redirect 301 to the url with final slash happens: enter image description here

So I cannot adopt the solution I have found in other posts on StackOverflow.. I mean something like this:

<rule name="TrailingSlash">
    <match url="^(.*)/$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
    </conditions>
    <action type="Redirect" url="{R:0}" />
</rule>

If I add this, obviously It goes into a loop and I get the error too_many_redirects...

I do not have nay other rule.. so What can I do? There is a standard rule on IIS that redirect to trailing slah when I point to directory? How can I remove it?

Simone
  • 2,304
  • 6
  • 30
  • 79
  • The final `/` is required. `trasporto-animali-domestici` does not map to a physical file on disk like index.html. It needs to add `/` at the end to prevent IIS from processing it as a static file. Then the request can enter the route in the application. ASP.NET or ASP.NET core. It is determined by route whether it is controller or action. Finally return to the razor page. If you don't want 2 redirects, you can add a `/` in `no-index-html` rule. `` – Bruce Zhang Feb 04 '22 at 02:48
  • Perhaps I haven't understood something. As you can see in the images above, both requests process a static file. So no action/controller nor a razor page are processed in those requests. – Simone Feb 04 '22 at 08:45
  • If so, I think failed request tracing is a great choice for you to view what happen during URL rewrite. – Bruce Zhang Feb 11 '22 at 06:02

0 Answers0