Rewrite rule to map locations to static files
What I want to do it rewrite urls for a bunch of static pages in a locations folder开发者_运维技巧 such that
/london
maps to the physical file if it exist in the locations folder eg.
/locations/london.aspx
Is this possible with url rewrite. I can't get the rule to work.
<rule name="Rewrite Locations">
<match url="^([_0-9a-z-]+)/*" />
<conditions>
<add input="/locations/{REQUEST_FILENAME}.aspx" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="/locations/{R:1}.aspx" />
</rule>
Many thanks,
Ian
For the IsFile to work you have to pass the right physical path and not the virtual path, you can do something like:
<rule name="Locations" stopProcessing="true">
<match url="^([_0-9a-z-]+)/*" />
<conditions>
<add input="{APPL_PHYSICAL_PATH}locations\{R:1}.aspx" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="/locations/{R:1}.aspx" />
</rule>
精彩评论