I'm using urlrewriting.net to redirect a cascading stylesheet image request. I've been trying without luck to do so. Here's the rewrite I added:
<add name="reportImagesRedirect"
virtualUrl="^~/estadisticas/(.*).png"
rewriteUrlParameter="ExcludeFromClientQueryString"
开发者_C百科 destinationUrl="~/images/$1"
ignoreCase="true" />
I'd like to know if there's something wrong with it. I'm trying to link all the http get requests made to one folder to be redirected to the images folder. So for instance when I make a request like this
http://localhost:8080/estadisticas/spines.png
I want the web server to look the image in
http://localhost:8080/images/spines.png
You need to flip it.
<add name="reportImagesRedirect"
destinationUrl="~/images/$1.png"
rewriteUrlParameter="ExcludeFromClientQueryString"
virtualUrl="^~/estadisticas/(.+).png$"
ignoreCase="true" />
Here is a little article I wrote on using UrlRewriting.Net for extensionless URL's.
EDIT: I changed the parameters a bit. if you are keeping the extensions, you need to have .png at the end of both the virtual and the destination
EDIT: You might also need to make the following modification to the system.webServer tag
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
You may need to set up a wildcard mapping. IIS will not forward requests for anything but ASP.NET files (.aspx, .asmx, .axd, .ashx, etc...) to the ASP.NET handler by default. Since your rewriter runs in the ASP.NET handler, the request for the image will never reach it. Adding a wildcard mapping forces IIS to let ASP.NET (and consequently, the rewrite handler) handle all requests, including images.
精彩评论