Forum Discussion
kalav Nimbostratus
Nimbostratus
Jan 26, 2021Redirect in iRule based on host and URI
 I have a virtual server on port 80 redirecting traffic to another vs on 443 via http 301 responses in an iRule:     if { [HTTP::host] equals "www.myexample.com" or [HTTP::host] equals "myexample.com"...
- Jan 26, 2021Hi Kev, The elseif on lines 4-5, must be after the line 23 in your code. 4. elseif { [HTTP::host] equals "blog.myexample.com"} {switch version: when HTTP_REQUEST { switch [HTTP::host] { "www.myexample.com" - "myexample.com" { HTTP::respond 301 Location "https://myexample.com[HTTP::uri]" } "blog.myexample.com" { switch [HTTP::uri] { "/ddc" - "/tree-tales" - "/made-here" - "/con21-reaction" { HTTP::respond 301 Location "https://uk.myexample.com" } "/btp" { HTTP::respond 301 Location "https://uk.myexample.com/projects/uk/b-2-p/" } "/bas" { HTTP::respond 301 Location "https://uk.myexample.com/projects/uk/b-a-s" } "/tenbelt" { HTTP::respond 301 Location "https://myexample.com/belt" } "/urban" { HTTP::respond 301 Location "https://myexample.com/U_L_C" } "/bhfl" { HTTP::respond 301 Location "https://uk.myexample.com/projects/uk/b_h_f_l" } default { HTTP::respond 301 Location "https://myexample.com[HTTP::uri]" } } } } }
kalav Nimbostratus
Nimbostratus
Jan 26, 2021Thanks Enes,
The first elseif on line 4 and 5 really should be at the end as a default, right. That makes sense.
I will see how the switch version works as well, get some testing done and get a reply back, but this makes sense so ought to work. Back shortly!
edit: that seems to have sorted me out. Thanks very much for the help!
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