Forum Discussion
jmeuse35_166730
Nimbostratus
Oct 22, 2014URL Rewrite - No redirection
A bit new to processing the irules and have a question which I hope the group can asisst with.
Scenario:
User URL: http://site.company.com/study1
F5 will rewrite the URL -> /ServiceStudyDB...
shaggy
Nimbostratus
Oct 22, 2014For rewriting redirect locations, check out https://devcentral.f5.com/articles/rewriting-redirects
- jmeuse35_166730Oct 22, 2014
Nimbostratus
As I work through this I think the issue is in the matching for the URI and replacement. Assume the request is: http://site.company.com/study1 and sending to the server as http://site.company.com/ServiceStudyDB. The server is sending back a 302 for ServiceStudyDB/login.aspx. Therefore, I think I need a wildcard that anything after /ServiceStudyDB will continue. ie: Would I not want to make sure that if anything is after the initial replacement that it continues? - shaggyOct 22, 2014
Nimbostratus
i'm not sure i understand - are you looking to retain the URI portion after the initial /xxx/? so /ServiceStudyDB/login.aspx would be /study1/login.aspx when it returned to a user? - jmeuse35_166730Oct 22, 2014
Nimbostratus
That is correct. On a nother platform I can rewrite the URL as "/study1(.*)" and replace with "ServiceStudyDB%1" and vice versa on the response. Sorry to make this confusing, but I believe this is where the redirect is looping. - jmeuse35_166730Oct 22, 2014
Nimbostratus
Ok got around it with the following: when HTTP_REQUEST { if {[HTTP::uri] contains "/study1"} { HTTP::header remove "Accept-Encoding" HTTP::header replace Location [string map -nocase {"study1" "ServicesStudyDB"} [HTTP::header Location]] HTTP::uri "/ServicesStudyDB" HTTP::uri [string map -nocase {"study1" "ServicesStudyDB"} [HTTP::uri]] STREAM::disable } } when HTTP_RESPONSE { if {[HTTP::header Content-Type] contains "text"}{ set study1_uri [string map -nocase {"/ServicesStudyDB" "/study1"} [HTTP::header "Location"]] HTTP::header replace Location $study1_uri HTTP::header replace Location [string map -nocase {"ServicesStudyDB" "study1"} [HTTP::header Location]] } } As there is content within the page that is referencing the /ServiceStudyDB virutal directory I will look at using a stream Irule to correct. Hoping this is easiest way. - shaggyOct 22, 2014
Nimbostratus
In regards to the redirect location specifically, if you look at the link above, the sample iRule has: HTTP::header replace Location "[string map {"http://" "https://"} [HTTP::header Location]]" String map basically does a search/replace of those two values, leaving the rest of the string unaltered. To rectify the redirect location (as long as /ServiceStudyDB/ only exists once in the URI), you could use HTTP::header replace Location "[string map {"/ServiceStudyDB/" "/study1/" } [HTTP::header Location]]" - jmeuse35_166730Oct 22, 2014
Nimbostratus
This seems to have done it.... Thank you for pointing me in the right direction. when HTTP_REQUEST { if {[HTTP::uri] contains "/study1"} { HTTP::header remove "Accept-Encoding" HTTP::header replace Location [string map -nocase {"study1" "ServicesStudyDB"} [HTTP::header Location]] HTTP::uri "/ServicesStudyDB" HTTP::uri [string map -nocase {"study1" "ServicesStudyDB"} [HTTP::uri]] STREAM::disable } } when HTTP_RESPONSE { if {[HTTP::header Content-Type] contains "text"}{ set study1_uri [string map -nocase {"/ServicesStudyDB" "/study1"} [HTTP::header "Location"]] HTTP::header replace Location $study1_uri HTTP::header replace Location [string map -nocase {"ServicesStudyDB" "study1"} [HTTP::header Location]] Replace 'old_text' with 'new_text' STREAM::expression {@ServicesStudyDB@study1@} Enable the stream filter for this response only STREAM::enable } }
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