繁体   English   中英

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

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

我正在将IIS重写器模块与我的web.config一起使用,并且只有在没有与请求匹配的实际文件夹/文件时才希望在子目录中重定向某些内容请求。 我怎样才能做到这一点?

有点晚了,但我会在这里给下一个找到这篇文章的人留下答案。

基本上你需要为重写规则添加几个条件。 例:

<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