简体   繁体   English

仅当文件/文件夹不存在时才重写路径

[英]Rewrite path only if file/folder does not exist

I am using the IIS Rewriter module with 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. 我正在将IIS重写器模块与我的web.config一起使用,并且只有在没有与请求匹配的实际文件夹/文件时才希望在子目录中重定向某些内容请求。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM