【问题标题】:Serve images from a directory but be accessed by a different URL path提供来自目录的图像,但可以通过不同的 URL 路径访问
【发布时间】:2013-09-14 21:42:00
【问题描述】:

如何在我的 web.config 中指定 URL 重写,从而从磁盘上的不同目录提供对图像的任何请求?

图像位于目录site-root\foo\bar\images。通常http://site-root/foo/bar/images/可以访问它们

我希望可以通过不同的 URL 访问图像,例如 http://site-root/img/

例如:

site-root\foo\bar\images\test.png

访问地点

http://site-root/img/test.png

我真的不需要过滤文件扩展名(png、gif、jpg 等),而只需要从img 请求的任何文件/资源​​都可以从真实目录中读取。

如何使用 ASP.NET web.config URL 重写或任何其他方法来实现此目的?

我要使用 web.config 解决方案,因为它将部署到 Windows Azure 网站。

【问题讨论】:

    标签: asp.net iis-7 web-config azure-web-app-service url-rewrite-module


    【解决方案1】:

    我过去通过在 IIS 中设置一个虚拟目录以将 URL 映射到特定文件夹来实现这一点。

    【讨论】:

    • 谢谢大卫。不幸的是,我使用的是 Windows Azure 网站,因此无权创建虚拟目录。
    • 对不起,我错过了你的问题。
    【解决方案2】:

    使用此 web.config 重写规则。

    <system.webServer>
    <rewrite>
      <rules>
        <rule name="Blog Images to Thier Real Location" stopProcessing="true">
          <match url="^img/(.*)" />
          <action type="Redirect" url="foo/bar/images/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
    </system.webServer>
    

    来自Carlos AG's blog post IIS 7.0 and URL Rewrite

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多