I would like to rewrite all paths, except those that are real files or real directories, and /api/*
to ~/Default.aspx
.
This is what I have so far:
<rules>
<rule name="default" patternSyntax="Wildcard">
<match url="*" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Default.aspx" />
</rule>
</rules>
The problem with this is that it rewrites /api/*
to Default.aspx
as well.
Try adding the following condition:
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" negate="true" pattern="(?:\/api)" />
</conditions>
I figured it out.
<rules>
<rule name="api" stopProcessing="true">
<match url="(.*api*)" ignoreCase="true" />
<action type="None" />
</rule>
<rule name="default" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Default.aspx" />
</rule>
</rules>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.