IIS rewrite URL

I cannot figure out how to solve this problem when rewriting a URL:

URLs after this pattern

app /(.*)

should redirect to app / index.cshtml

However, the application folder contains resources such as subfolders, js files, and html files. They should be ignored and no redirection should be made.

Here's how Ive done it:

<rewrite> <rules> <rule name="Rule 1" stopProcessing="true"> <match url="app/(.*/.js)" /> <action type="None" /> </rule> <rule name="Rule 2"> <match url="app/(.*)" /> <action type="Rewrite" url="app/index.cshtml" /> </rule> </rules> </rewrite> 

I was only trying to exclude js files at the moment, but when I look at the / someurl application, I get an error because one of the js files cannot be loaded. I think because the first rule does not work.

You can help?

+1
source share
1 answer

Here is what I did:

 <rule name="Rule1"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{URL}" negate="true" pattern="\.axd$" /> <add input="{URL}" negate="true" pattern="\.jpg$" /> <add input="{URL}" negate="true" pattern="\.gif$" /> <add input="{URL}" negate="true" pattern="\.png$" /> <add input="{URL}" negate="true" pattern="\.css$" /> <add input="{URL}" negate="true" pattern="\.ico$" /> <add input="{URL}" negate="true" pattern="\.cur$" /> <add input="{URL}" negate="true" pattern="\.js$" /> <add input="{URL}" negate="true" pattern="\.xml$" /> <add input="{URL}" negate="true" pattern="\.svg$" /> <add input="{URL}" negate="true" pattern="\.ttf$" /> <add input="{URL}" negate="true" pattern="\.eot$" /> <add input="{URL}" negate="true" pattern="\.woff$" /> <add input="{URL}" negate="true" pattern="\.html$" /> </conditions> <action type="Rewrite" url="app/index.cshtml" /> </rule> 
+2
source

Source: https://habr.com/ru/post/1487281/


All Articles