You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IIS规则配置求助:将documents目录内容重定向至/images/documents

解决IIS URL重定向:将/documents下所有内容转到/images/documents

问题描述

需要将域名下/documents目录及其所有子文件夹、文件,永久重定向到/images/documents路径。例如:

  • 原地址:domain.com/documents/news/2024/file.pdf
  • 目标地址:domain.com/images/documents/news/2024/file.pdf

之前尝试的规则仅针对/documents/news/子目录,无法覆盖所有/documents下的内容,需要调整规则。

正确的URL重写规则

<rule name="Redirect Documents to Images/Documents" stopProcessing="true">
    <match url="^documents/(.*)$" />
    <action type="Rewrite" url="images/documents/{R:1}" redirectType="Permanent"/>
</rule>

规则说明

  • 匹配规则:^documents/(.*)$ 会匹配所有以documents/开头的URL路径,(.*)会捕获documents/之后的所有内容(包括子目录、文件名),存储到变量{R:1}中。
  • 重定向动作:将匹配到的URL重写到images/documents/{R:1},也就是把原路径中documents/替换为images/documents/,redirectType="Permanent"表示使用301永久重定向,对SEO更友好。
  • stopProcessing="true":确保这条规则处理完成后,不再执行后续的重写规则,避免冲突。

内容的提问来源于stack exchange,提问作者iBison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 23:42:01