Forum Discussion
looking for an opinion on this https redirect irule
Hey Everybody, I wonder if I can get your opinion on my irule.
I am tasked with creating an http to https redirect but at the same time they would like to make some tweaks for SEO reasons. we are looking for the following:
1)If it comes in as placeone.com with no uri -go to https://www.placetwo.com/subplace/ with no uri 2)If it comes in as placeone.com with a uri -go to https://placeone.com with the uri attached. 3)If it comes in as www.placeone.com with no uri -go to https://www.placetwo.com/subplace/ with no uri 4)If it comes in as www.placeone.com with a uri -go to https://placeone.com with the uri attached 5)Everything left -go to https://placeone.com with the uri attached
I am using:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "www.placeone.com" } { if { [HTTP::uri] eq "/" } { HTTP::respond 301 Location "https://www.placetwo.com/subplace/" } } if { [string tolower [HTTP::host]] eq "placeone.com" } { if { [HTTP::uri] eq "/" } { HTTP::respond 301 Location "https://www.placetwo.com/subplace/" } else { HTTP::respond 301 Location "https://www.placeone.com[HTTP::uri]" } } }
It's a little bit complicated for me so I don't know if rule or even the syntax will work.
Thanks!
7 Replies
- ekaleido
Cirrus
I am assumig you don't want to actually redirect them to the URL/URI they originally requested, so rather than redirect, I made the action to simply send the traffic to the relevant pool name. In this example, a pool named "whatever." Using switch will allow you to expand the concept should you require other redirects later.
when HTTP_REQUEST {
set host [string tolower [HTTP::host]]
if { $host = "www.placeone.com" || "placeone.com" } {
switch [HTTP::uri] {
"/" { HTTP::respond 301 Location "https://www.placetwo.com/subplace/" }
default { pool whatever }
}
}- Sokol_69126
Nimbostratus
thank you for your answer! I neglected to note that https://www.placetwo.com/subplace/ is outside of this f5. In that case, I am forwarding it to the company that owns us. how would I adapt this to that case?
Thanks again!!!
- Vijay_E
Cirrus
The above iRule should work in terms of sending a redirect to the client and the client will initiate the connection again to the new location.
- ekaleido_26616
Cirrocumulus
I am assumig you don't want to actually redirect them to the URL/URI they originally requested, so rather than redirect, I made the action to simply send the traffic to the relevant pool name. In this example, a pool named "whatever." Using switch will allow you to expand the concept should you require other redirects later.
when HTTP_REQUEST {
set host [string tolower [HTTP::host]]
if { $host = "www.placeone.com" || "placeone.com" } {
switch [HTTP::uri] {
"/" { HTTP::respond 301 Location "https://www.placetwo.com/subplace/" }
default { pool whatever }
}
}- Sokol_69126
Nimbostratus
thank you for your answer! I neglected to note that https://www.placetwo.com/subplace/ is outside of this f5. In that case, I am forwarding it to the company that owns us. how would I adapt this to that case?
Thanks again!!!
- Vijay_E
Cirrus
The above iRule should work in terms of sending a redirect to the client and the client will initiate the connection again to the new location.
- VernonWells
Employee
I believe the following is clearer and it avoids multiple expansions of
:string to lower [HTTP::host]when HTTP_REQUEST { if { [HTTP::uri] eq "/" } { switch [string tolower [HTTP::host]] { "placeone.com" - "www.placeone.com" { HTTP::respond 301 Location "https://www.placetwo.com/subplace/" return } } } HTTP::respond 301 Location "https://www.placeone.com[HTTP::uri]" }You may also consider using a Local Traffic Policy. This is particularly true if you are running 12.x.
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