views:

306

answers:

2

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"
                    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

+1  A: 

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>
rockinthesixstring
Um... the order of the attributes makes absolutely NO difference.
Chris
I edited my question with an example of the result I'm expecting in case it wasn't clear enough.
Raúl Roa
Why would you down vote my answer. I didn't "JUST" rearrange the order of the attributes. I changed the way the VirtualUrl and the destinationUrl's were written. The VirtualUrl needs the Regex, while the DestinationUrl needs to be where the Actual file is located... it must contain the extension as well.
rockinthesixstring
Ok, there's a problem with the regex... since the request it's being made to ...\estadisticas\^\images\spines.png, instead of ...\images\spines.png. I fixed it removing ^
Raúl Roa
Yup, you're right Raul. I didn't notice that bit since I was just modifying his xml. I'll edit now.
rockinthesixstring
A) I didn't downvote Rock and B) flagging is not really for that. You both could use a little maturity when partaking in community discussions such as S/O
Chris
Sorry Chris. I didn't flag or down vote anyone, Just bitched a little when my answer was down voted when it wasn't wrong.
rockinthesixstring
A: 

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.

Chris
I don't recommend wildcard mappings, it's just not needed
rockinthesixstring
also IIS7 and .NET 3.5 allow you to do this [runAllManagedModulesForAllRequests="true"] from within your web.config and alleviates the need for Wildcard Mapping all together.
rockinthesixstring
@Rock: it absolutely IS needed if you're running IIS 6 or IIS 7 in classic mode. I never assume any particular version. Also, lose the whiny attitude. I see that you downvoted my answer because you think I downvoted yours, which is not the case. Not very mature, IMO.
Chris
@Chris. Nope, didn't down vote you.
rockinthesixstring