Forum Discussion
kalav
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, 2021
Hi 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]" } } } } }
Jan 26, 2021
Hi 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]" }
}
}
}
}
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
