未应用 IIS 7 URL 重写规则
我有一个 .net 4.0 Web 应用程序托管在 IIS7 服务器上。
阅读后:http://learn. iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/ 关于从另一台服务器提供静态内容,以便不会随每个静态文件请求一起发送 cookie,我尝试过但没有取得多大成功。
这是 web.config 文件中写入的部分:
<system.webServer>
<rewrite>
<rules>
<rule name="images" stopProcessing="true">
<match url="^images/(.*)$" />
<action type="Rewrite" url="http://static-server.com/images/{R:1}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
定义此规则后,图像文件夹中文件的每个链接都应重写到静态服务器 URL 中。但这根本不起作用,现在 images 文件夹中的每个图像都会返回 404 未找到。知道什么可能导致这种行为,或者知道如何从不同服务器的特定文件夹中提供文件,而不必使用大量代码并更改所有链接以链接到静态服务器吗?
我也尝试使用重定向操作类型而不是重写操作,这实际上有效,但它违背了我尝试在不同服务器上提供文件的原因(这样请求将发送到我的动态内容服务器)所有必需的 cookie 并被重定向到静态服务器,这实际上比从动态内容服务器提供图像更糟糕)。
I have a .net 4.0 web application hosted on IIS7 server.
After reading this: http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/ about serving static content from another server, so that cookies aren't sent with every request for a static file, i tried it out but without much success.
This is the part written in the web.config file:
<system.webServer>
<rewrite>
<rules>
<rule name="images" stopProcessing="true">
<match url="^images/(.*)$" />
<action type="Rewrite" url="http://static-server.com/images/{R:1}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
With this rule defined, every link to a file in the images folder should be rewriten into the static-server URL. But this doesn't work at all, now every image that is in the images folder returns a 404 not found. Any idea on what could be causing this behavior or a different solution on how to serve files from a specific folder from a different server without having to go trough tons of code and change all the links to link to the static server?
I did also try using the Redirect action type instead of the Rewrite action, which actually worked, but it defies the reason why i'm trying to serve the files on a different server (this way the request is sent to my dynamic content server with all the required cookies and is redirected to the static-server which is actually worse than serving the images from the dynamic content server).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为仅靠这条规则并不能为您解决这个问题。它可能不会重写发送给用户的页面中的链接。
您链接到的文章建议您“与 IIS应用程序请求路由模块”。路由模块实际上更改发送到客户端的文件内的链接。
I don't think that rule alone will solve this problem for you. It probably doesn't rewrite links in pages that are sent to users.
The article you linked to suggests that you do this "together with the IIS Application Request Routing module". It's the routing module that actually changes links within files sent to the client.