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

Mar*_*ios 12 iis rewrite web-config

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

ade*_*mar 26

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

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

<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>
Run Code Online (Sandbox Code Playgroud)

  • 但没有保存我的屁股:p (2认同)