[英]web.config: rewrite only if *rewritten* path exists
I want to do a rewrite from http://example.com/assets/file.ext
to /sites/example.com/assets/file.ext
only if that rewritten path exists. 我想从
http://example.com/assets/file.ext
重写为/sites/example.com/assets/file.ext
只有在重写路径存在的情况下才会重写 。 I can do it more broadly like so: 我可以更广泛地这样做:
<rules>
<rule name="assets" stopProcessing="true">
<match url="^assets/(.+)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
</conditions>
<action type="Rewrite" url="sites/{C:2}/assets/{R:1}" />
</rule>
</rules>
but when I add a condition <add input="{REQUEST_FILENAME}" matchType="IsFile" />
it will try to match a file at the original path. 但是当我添加条件
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
,它将尝试匹配原始路径上的文件。
Can this be done? 可以这样做吗?
The rule you want is I believe approximately this: 你想要的规则是我相信这个:
<add input="{APPL_PHYSICAL_PATH}sites\{C:2}\assets\{R:1}" matchType="IsFile" />
This has to come after the host condition, obviously, so that the backreference is available. 显然,这必须在主机条件之后,以便反向引用可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.