Forum Discussion
mark_57891
Nimbostratus
Sep 16, 2009Rewrite URLs question
Hello all. I'm trying to create an iRule to perform URI rewrite when a match is encountered. Essentially, I want to rewrite URL 1 into URL 2, where the wi_id=value will constantly change.
URL 1: http://myoriginalappserver/gopwfbasic?wi_id=935461&email=X
URL 2: http://mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?wi_id=935461&email=X
I need to grab the "wi_id=935461&email=X" string and use it to format new URLs. I have an iRule which, when the criteria is met (URI contains /gopwfbasic), uses string trim to capture the string and then replace the URL. However, it does not seem to be working as intended. Depending on the length of the requestURI, not all of the string is captured.
Does anyone have a recommendation / suggestion? Thanks,
------------
switch -glob [HTTP::uri] {
"/gopwfbasic?*" {
set requestURI "/gobwfbasic?"
}
"/gopwfcomplex?*" {
set requestURI "/gopwfcomplex?"
}
default {
log local0. "no match"
}
}
If the following variable exists (requestURI), then criteria has been met and the URL should be re-written
if {[info exists requestURI]}{
set trimURI [string trimleft [HTTP::uri] "$requestURI"]
log local0. "trimURI: $trimURI"
set newURI "mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?$trimURI"
log local0. "Client IP: [IP::client_addr]. Updated URI: http://$newURI"
HTTP::redirect "http://$newURI"
}
------------
- The_Bhattman
Nimbostratus
How about the following:when HTTP_REQUEST { if { [HTTP::query] starts_with "wi_id" } { switch -glob [HTTP::uri] { "/gopwfbasic?*" - "/gopwfcomplex?*" { set rewrite [substr [HTTP::query] 0 0] http::redirect "http://mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?$rewrite" } } } }
- The_Bhattman
Nimbostratus
Hi Mark,when HTTP_REQUEST { if { [HTTP::query] starts_with "wi_id" } { switch -glob [HTTP::uri] { "/gopwfbasic?*" - "/gopwfcomplex?*" { http::redirect "http://mynewappserver/webdynpro/dispatcher/sap.com/zmobile/Zmobile?[HTTP::query]" } } } }
- mark_57891
Nimbostratus
Thank you very much for your prompt responses. I have modified the iRule using your example and we are currently testing. - The_Bhattman
Nimbostratus
Great. Let us know how it goes. We would love to hear the results. - mark_57891
Nimbostratus
The iRule works exactly as intended. Thank you again for your assistance! - mark_57891
Nimbostratus
The iRule works exactly as intended. Thank you again for your assistance! - mark_57891
Nimbostratus
The iRule works exactly as intended. Thank you again for your assistance! - The_Bhattman
Nimbostratus
No Problem. I am glad it worked out for you.
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