Forum Discussion
Performing a redirect using string map
I believe you can use HTTP::redirect and just specify the new host without the protocol. I think you could process the string a little more quickly with an explicit string replace instead of string map, too, and save the system from having to search the string for a pattern because you know it's always going to be the first 31 characters of the string.
So instead, you could do something like this:
if { [HTTP::path] starts_with {/shop/wedding-registry/product/} } {
set uri [string replace [HTTP::uri] 0 30 {/shop/registry/wedding/product/}]
HTTP::redirect "//$uri"
}
I imagine it would be even faster to use a Rewrite profile, but if you're already processing iRules, it might be more discoverable to keep the logic all together here.
Edit: As noted in the docs for HTTP::redirect, it does give you a 302 response code, so if you want 301, you'd have to use HTTP::respond instead.
Just to make the reference convenient, here's the HTTP module documentation page.
- Rory_Hewitt_F5_Sep 09, 2015
Cirrus
Michael J, I didn't know you could do a relative URL redirect. You learn something new every day! @oshaughnessy, yeah, I'd already seen the limitation in HTTP::redirect about it only doing a 302 - that's why I used HTTP::respond. But it's useful info for the next person, so thanks for that.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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