iRule: modifying the uri without a redirect
In this case the user wants to change the uri of a HTTP request without forcing a redirect from the client.
We have a unique situation where a client-based DLL is uploading a file to our website. For reasons beyound my control I need to change the destination url without a redirect. When I use a redirect the payload (file to upload) is lost because the DLL is not smart enough to resubmit file for upload.
This can be done with the HTTP::uri command fairly easily. The fun starts with how you go about doing it.
Let's say you want to replace the entire URI with something new. For this example, let's say we need to replace "/foo" with "/bar". This can be done by the following:
when HTTP_REQUEST { if { [HTTP::uri] equals "/foo" } { HTTP::uri "/bar" } }
But, what happens if you are working with a URI containing get parameters? This way you only know the beginning of the uri. Again, no problem. In this example the following iRule will replace any uri starting with "/foo" with "/bar"
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/foo" } { HTTP::uri "/bar[string range $uri 4 end]" } }
-Joe
- It should work as is. The HTTP::uri command takes two forms, if enclosed in braces with no arguments, it returns the URI. If it is passed a parameter then it uses the passed in variable as the new URI.
- There are two ways to modify the URI.
- Doh, I always forget that HTTP::host doesn't have a write method. This should do it for you.
- Here you go:
- Hey Dan, that seems odd. The "equals" comparison should not succeed for the uri of "/psp/App/?cmd=login" as shown in your first log statement. Move this over to the iRules forum and we can diagnose it further.
- Jessy, when you said you started it, what did that mean. did you get the error when saving the iRule or was that error put in the log when a request was made through the Virtual Server using that iRule? I don't see anything wrong with your iRule as it's written to cause that error. Especially since I don't see the token "alumno" anywhere outside of the middle of the URL in the redirect statement.
- Adrian03NimbostratusHi,
- DenisGrimard_34Historic F5 AccountI needed to do it like so to catch it properly:
- Miles_Raymond_1NimbostratusI'm not sure how this is supposed to work, but it doesn't seem to actually modify the [HTTP::uri] variable as in this example: