0

我们正在将旧应用程序迁移到 ASP.NET MVC,但在旧应用程序中,图像文件夹位于应用程序的根目录中,因此要引用图像,路径将是 /images/imagename.png,但我们想要移动在新应用程序中将图像添加到 /Content/images 中,但我们不想更改所有 css 和 html 中的路径。

有没有办法重写图像文件夹,以便每个转到 /images 的 URL 都转到 /Content/images ?

4

1 回答 1

3

Use URL Rewrite. You need to install it via WebPI, then add the following to your web.config in system.webServer:

 <rewrite>
    <rule name="Old Images" stopProcessing="true">
      <match url="^images/(.+)$" ignoreCase="true" />
      <action type="Rewrite" url="content/images/{R:1}" appendQueryString="true" />
    </rule>
 </rewrite>
于 2013-08-14T23:23:20.020 回答