Forum Discussion
tidenz_92110
Nimbostratus
Mar 24, 2010Location rewrite redirect 302 string issues
New to string commands and irules but i am trying to do a header replace without using regex.
In the redirect location header I am trying to strip out the protocol and the hostname to make the redirect relative to the application for testing
(yes i know the RFC is to have a FQDN in the location header) but the apps guys want it.
So the current location header looks like
http://company.com/app1/sad.do
i want
/app1/sad.do
note this will be used on multiple domains so it maybe company1 or company2 etc.
I have tried to read it into a variable and then use a findstr to find the first trailing slash but i keep matching the / in "http:/" is there a way to miss the first 2 // and find the last /
The irule is as follows
when HTTP_RESPONSE {
set newloc [HTTP::header Location]
log local0.debug "$newloc"
set rewriteloc [findstr $newloc "/" 9 ]
log local0.debug "$rewriteloc"
if { [HTTP::is_redirect] }{
HTTP::header replace Location "$rewriteloc"
}
Thanks
- hoolio
Cirrostratus
Hi Tidenz,when HTTP_RESPONSE { Check if response is a redirect if { [HTTP::is_redirect] }{ Use scan to check for http://$host/$uri, saving the matches the leading / of the URI will be trimmed, so we need to append it in the Location rewrite if {[scan [HTTP::header Location] {http://%[^/]/%s} host uri] == 2}{ HTTP::header replace Location "/$uri" } } }
- tidenz_92110
Nimbostratus
Thanks for the prompt response hoolio, i am not aware of the redirects including https but knowing the dev's it maybe a option later down the line. I will run with the current irule for now.
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