Forum Discussion
briancapps_1029
Nimbostratus
Sep 21, 2010iRule redirect - change domain, path but keep unique ID
I'm having trouble getting an iRule right that redirects domain, modifies path, but maintains a trailing unique identifier. I intend to redirect:
http://documents.test.com/retrieve.asp?guid=43w232w398s-sd
to
http://platform.test.com/Servicepages/RetrieveDocument.aspx?did=43w232w398s-sd
Where the value after the = will always be variable.
Thoughts?
12 Replies
- briancapps_1029
Nimbostratus
Here's my shot at it so far. It's just not working the way I would hope. Seems to ignore the host redirect and the uri string map as well.
when HTTP_REQUEST {if {[HTTP::host] equals "documents.test.com"} {
HTTP::redirect http://platform.test.com"}if { [HTTP::uri] starts_with "/retrieve.asp?guid"}{
HTTP::uri [string map {/retrieve.asp?guid /Servicepages/RetrieveDocument.aspx?did} [HTTP::uri]]
}
} - briancapps_1029
Nimbostratus
Ok, got it figured out, in case this helps anyone and so nobody wastes any time with it...
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/retrieve.asp"}{
HTTP::redirect "http://[string map {documents.test.com/retrieve.asp?guid= platform.test.com/Servicepages/RetrieveDocument.aspx?did=} [string tolower [HTTP::host]][HTTP::uri]]"
}
} - Lambera_53322
Nimbostratus
Ive been directed to take over this project for Capps since he has left the business. This is still an open question and his solution does not work.
To recap.
2 Domains (Hosts) with there own Paths and only a portion of the query will be the same. Both services have access to the same documents via the ID, hince why we only need to maintain the ID, this ID is random based on the associated document, so the number can change at any time.
http://doc.qa.domain.com/retrieve.a...4
http://doc.qa.domain.com/Servicepag...4 - Lambera_53322
Nimbostratus
Well it looks like he was pretty close to a solution as the following works but with some minor issues:
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/retrieve.asp"}{
HTTP::redirect "http://[string map {".../retrieve.asp?guid=" ".../Servicepages/RetrieveDocument.aspx?did="} [string tolower [HTTP::host]][HTTP::uri]]"
}
}
What I am unable to account for is that R in retrieve.asp could either be upper or lower. Currently in QA I am using two Irules on the VIP due to this issue so that it will catch both upper and lower. I would like to consolidate this into a single Irule. - Colin_Walker_12Historic F5 AccountIt sounds like you need the string tolower command. For a case insensitive comparison try:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/retrieve.asp"}{ HTTP::redirect "http://[string map {".../retrieve.asp?guid=" ".../Servicepages/RetrieveDocument.aspx?did="} [string tolower [HTTP::host]][HTTP::uri]]" } }
Colin - Lambera_53322
Nimbostratus
Thanks, I tried your sugestion but this seems to throw this into an infinate loop when accessing links that have a upper R in the asp page. - hoolio
Cirrostratus
Can you try this instead?when HTTP_REQUEST { Check for requests to /retrieve.asp if { [string tolower [HTTP::path]] eq "/retrieve.asp"}{ Redirect the request to /Servicepages/RetrieveDocument.aspx with the guid parameter value set as did HTTP::redirect "/Servicepages/RetrieveDocument.aspx?did=[URI::query "?&[HTTP::query] &guid]" } }
Aaron - Lambera_53322
Nimbostratus
line 8: [parse error: missing close-bracket] [[URI::query "?&[HTTP::query] &guid]"
] - Michael_Yates
Nimbostratus
Can you try this:when HTTP_REQUEST { Check for requests to /retrieve.asp if { [string tolower [HTTP::path]] eq "/retrieve.asp"}{ Redirect the request to /Servicepages/RetrieveDocument.aspx with the guid parameter value set as did HTTP::redirect "/Servicepages/RetrieveDocument.aspx?did=[URI::query [HTTP::query] "guid" ]" } } - hoolio
Cirrostratus
Sorry, there was a missing double quote:when HTTP_REQUEST { Check for requests to /retrieve.asp if { [string tolower [HTTP::path]] eq "/retrieve.asp"}{ Redirect the request to /Servicepages/RetrieveDocument.aspx with the guid parameter value set as did HTTP::redirect "/Servicepages/RetrieveDocument.aspx?did=[URI::query "?&[HTTP::query]" &guid]" } }
Michael, the ?&[HTTP::query] and &guid parts are necessary to work around a bug in the URI::query command. See the bottom of the URI::query wiki page for details:
http://devcentral.f5.com/wiki/default.aspx/iRules/uri__query.html
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects