【问题标题】:Forwarding requests for relocated static content转发重定位静态内容的请求
【发布时间】:2011-08-27 15:10:51
【问题描述】:

我在一个站点上有一堆静态内容,这些内容始终位于根目录中,例如http://mysite.com/smiley.gif。我想把它全部移到一个子目录http://mysite.com/images/smiley.gif

问题是多年的内容指向第一个 URL。将这些请求转发到新位置的最佳方式是什么?

【问题讨论】:

    标签: asp.net asp.net-mvc iis-7 http-headers static-content


    【解决方案1】:

    我们最近正是这样做的。我们最终通过 IIS 使用了重写规则,因为它们很早就在管道中应用,因此对性能的影响最小。查看UrlRewrite module 了解更多信息。

    刚刚打开我们的规则,在 IIS 中安装重写模块后,将以下内容添加到根 Web.config。此规则将重写所有 *.gif 请求,您可能需要对其进行一些调整。

    <system.webserver>
        <rewrite>
            <rules>
                <clear />
                <rule name="gif" stopProcessing="true">
                    <match url="^(.*).gif" />
                    <action type="Rewrite" url="/images/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webserver>
    

    【讨论】:

      猜你喜欢
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 2011-02-25
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多