Forum Discussion
Shawn_Salyers_8
Apr 27, 2011Nimbostratus
URI Redirect with 301
Hello and thank you for the help....
I have a need to take the incoming request and replace portions of the URI and redirect to ta different pool, which is currently working with the following iRule:
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] eq "devurl.mycompany.com" } {
if { [HTTP::uri] contains "/landing/sections/innovation/article/" } {HTTP::uri [string map {/landing/sections/innovation/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/lifestyle/article/" } {HTTP::uri [string map {/landing/sections/lifestyle/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/managing/article/" } {HTTP::uri [string map {/landing/sections/managing/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/marketing/article/" } {HTTP::uri [string map {/landing/sections/marketing/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/money/article/" } {HTTP::uri [string map {/landing/sections/money/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/technology/article/" } {HTTP::uri [string map {/landing/sections/technology/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/the-world/article/" } {HTTP::uri [string map {/landing/sections/the-world/article /articles} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/innovation/videos/" } {HTTP::uri [string map {/landing/sections/innovation/videos /videos} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/lifestyle/videos/" } {HTTP::uri [string map {/landing/sections/lifestyle/videos /videos} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/managing/videos/" } {HTTP::uri [string map {/landing/sections/managing/videos /videos} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/marketing/videos/" } {HTTP::uri [string map {/landing/sections/marketing/videos /videos} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/money/videos/" } {HTTP::uri [string map {/landing/sections/money/videos /videos} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/technology/videos/" } {HTTP::uri [string map {/landing/sections/technology/videos /videos} [HTTP::path]][HTTP::query]}
elseif { [HTTP::uri] contains "/landing/sections/the-world/videos/" } {HTTP::uri [string map {/idea-ub/sections/the-world/videos /videos} [HTTP::path]][HTTP::query]}}
pool POOL-X001
}
What I am being asked to do now, is add a 301 to the redirect.
Any help would be greatly appreciated.
--Shawn
- hooleylistCirrostratusYou can change from HTTP::uri to HTTP::respond 301 Location $new_location. If you're using string map to dynamically set the new location, you can use this:
- Joel_MosesNimbostratusHoolio sweeps in for the win. üòÜ
when HTTP_REQUEST { if {[string tolower [HTTP::host]] eq "devurl.mycompany.com" } { switch -glob [string tolower [HTTP::uri]] { "/landing/sections/innovation/article/*" { HTTP::respond 301 Location [string map {/landing/sections/innovation/article /articles} [HTTP::path]][HTTP::query] } "/landing/sections/lifestyle/article/*" { HTTP::respond 301 Location [string map {/landing/sections/lifestyle/article /articles} [HTTP::path]][HTTP::query] } } pool POOL-X001 } }
- Colin_Walker_12Historic F5 AccountWith switch not only will things become far more legible (in my personal opinion, anyway) but you'll also see a pretty significant performance improvement (fact, not opinion). It's definitely worth taking a look.
- Shawn_Salyers_8NimbostratusThanks for all the great help! I couldn't have gotten it working without you guys!
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