开发者

Rewrite rule to map locations to static files

开发者 https://www.devze.com 2023-01-08 23:15 出处:网络
What I want to do it rewrite urls for a bunch of static pages in a locations folder开发者_运维技巧 such that

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消