Forum Discussion
Ethan_West_1101
May 01, 2008Historic F5 Account
301 to Redirect
Hi All,
I am trying to get an iRule working that will redirect on a 301 to the Specific Host URI requested. This is for an application that users request is without the trailing slash (http://www.somesite.com/stcokquotes) in turn the servers respond with 301.
My question how do I write the iRule to respond with a 302 for example and preserve the Host and URI? I am looking at a previous post that works for me but is inserting the Header Value Location from the server which obviously breaks the app. How do I preserve the Host / URI in the inital request.
when HTTP_RESPONSE {
Check if the server response is a 302
if {[HTTP::status] == 301}{
Send a 301 response to the client with the Location header value from the server's response HTTP::respond 302 Location [HTTP::header value Location]
}
}
Thanks for the help in advance.
- hoolio
Cirrostratus
Can you clarify this a bit/add an example or two? What do you want to rewrite in the app's response? What do you want to rewrite it to? - Ethan_West_1101Historic F5 AccountHi Hoolio,
- hoolio
Cirrostratus
If you always want to use the same domain in the redirect, you can set it statically. Else, if it needs to change dynamically according to what the client requested, you'd need to save the host header value on every request to use in rewriting the redirects. If you know the string you want to search for it would be more efficient to hardcode that as well. - Ethan_West_1101Historic F5 AccountYes I do know the strings they will always be the same. In fact it's only going to be one per Virtual Server.
- hoolio
Cirrostratus
If it's static strings, the change is pretty simple. Just look in responses for a 30x status, then set the Location header to a value with the app's host replaced with the outside host name.when HTTP_RESPONSE { Check for redirects if {[HTTP::is_redirect]}{ Log a debug message. Comment this out when done testing. log local0. "[IP::client_addr]:[TCP::client_port]: Updating Location header from [HTTP::header value Location], \ to: [string map -nocase {find replace} [HTTP::header value Location]]" Replace the Location header with the new host name HTTP::header replace Location [string map -nocase {find replace} [HTTP::header value Location]] } }
- Ethan_West_1101Historic F5 AccountThanks Aaron,
- hoolio
Cirrostratus
Good to hear. Make sure to comment out the log statement to save resources, once you're done testing.
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