【问题标题】:iis rewrite virtual subfolder pathiis 重写虚拟子文件夹路径
【发布时间】:2020-08-19 23:57:36
【问题描述】:
  1. 我尝试通过 IIS 上的重写模块更改子文件夹路径(虚拟目录)
  2. 我想将 url 路径从“www.site.com/photos/20/be2f-8ed24a0d1a9a.jpg”更改为“www.site.com/photos/20_new/be2f-8ed24a0d1a9a.jpg”,其中“/photos”是虚拟目录和“/20”它的子文件夹
  3. 我写规则:
    <rewrite>
      <rules>
        <clear/>
        <rule name="photo path rewrite" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{QUERY_STRING}" pattern="/photos/20/(.*)" />
          </conditions>
          <action type="Redirect" url="{HTTP_HOST}/photos/20_new/{C:1}" redirectType="Temporary" />
        </rule>
      </rules>
      <rewriteMaps></rewriteMaps>
    </rewrite>
  1. 我做错了什么?谢谢:)

【问题讨论】:

标签: iis path url-rewriting virtual subdirectory


【解决方案1】:

您能解释一下您要重定向的 URL 属于 src 属性还是您只想直接访问该 URL?

如果直接访问 URL,您只需将条件输入从 {QUERY_STRING} 更改为 {REQUEST_URI}。

如果这个url属于html img标签中的“src”属性,那么你可以试试这个outbound rule。

<rewrite>
        <outboundRules>
            <rule name="outbound rule" preCondition="IsImage">
                <match filterByTags="Img" pattern="(.*)" />
                <conditions>
                    <add input="{REQUEST_URI}" pattern="/photos/20/(.*)" />
                </conditions>
                <action type="Rewrite" value="{HTTP_HOST}/photos/20_new/{C:1}" />
            </rule>
            <preConditions>
                <preCondition name="IsImage">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>

【讨论】:

    猜你喜欢
    • 2013-05-09
    • 2020-02-17
    • 1970-01-01
    • 2017-08-27
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    相关资源
    最近更新 更多