开发者

Rewrite path only if file/folder does not exist

开发者 https://www.devze.com 2023-02-05 09:11 出处:网络
I am using the IIS Rewriter module wi开发者_如何学Pythonth my web.config, and would like to redirect certain requests for content in a subdirectory only if there isn\'t an actual folder/file that alre

I am using the IIS Rewriter module wi开发者_如何学Pythonth my web.config, and would like to redirect certain requests for content in a subdirectory only if there isn't an actual folder/file that already matches the request. How can I do this?


A little late but I'm going to leave an answer here for the next person that find this post.

Basically you need to add a couple of conditions to the rewrite rule. Example:

<rule name="Remove trailing slash" stopProcessing="true">
    <match url="(.*)/$"/>
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{R:1}" appendQueryString="true"/>
</rule>
0

精彩评论

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