Forum Discussion
Irule - HTTP redirect with a rewrite.
Guys,
I have a HTTP(S) redirect requirement ; I am migrating Apache load balancer webservices to F5.
The requirement is to redirect
https://webname.com/aaa/Default.aspx?ID:CUST=123 to - https://webname.com/bbb/default.aspx?ID:CUST=123
Where the paramenters right of the question mark are different across the URLs and need to remain as per the original URL. Have tried various attempts e.g.
elseif { [class match [HTTP::uri] starts_with datagroup_redirect] } { HTTP::respond 302 Location "https://[HTTP::host][HTTP::uri [string map {"/aaa/Default" "/bbb/default"} [HTTP::uri]]]" }
But cannot get this to work Any help would be much apppreciated … this one is killing me.
Append
to your redirect destination (sample below). The only problem with this approach is that you will always be redirected to a location with ?-symbol at the end, whether you have any query parameters in the original request or not.?[HTTP::query]
HTTP::respond 302 Location "https://webname.com/bbb/default.aspx?[HTTP::query]"
If the above bothers you, you can write a condition to determine if the question mark should be appended or not as follows
Determine if original request contains query parameters if { [HTTP::query] ne "" }{ set myQuery "?[HTTP::query]" } else { set myQuery "" } your condition goes here HTTP::respond 302 Location "https://webname.com/bbb/default.aspx$myQuery"
- Hannes_Rapp_162Nacreous
Append
to your redirect destination (sample below). The only problem with this approach is that you will always be redirected to a location with ?-symbol at the end, whether you have any query parameters in the original request or not.?[HTTP::query]
HTTP::respond 302 Location "https://webname.com/bbb/default.aspx?[HTTP::query]"
If the above bothers you, you can write a condition to determine if the question mark should be appended or not as follows
Determine if original request contains query parameters if { [HTTP::query] ne "" }{ set myQuery "?[HTTP::query]" } else { set myQuery "" } your condition goes here HTTP::respond 302 Location "https://webname.com/bbb/default.aspx$myQuery"
- Basil_Parsley_1Nimbostratus
Thanks - the more simplex answer met my requirements, and worked ; appreciated the detail.
- Hannes_RappNimbostratus
Append
to your redirect destination (sample below). The only problem with this approach is that you will always be redirected to a location with ?-symbol at the end, whether you have any query parameters in the original request or not.?[HTTP::query]
HTTP::respond 302 Location "https://webname.com/bbb/default.aspx?[HTTP::query]"
If the above bothers you, you can write a condition to determine if the question mark should be appended or not as follows
Determine if original request contains query parameters if { [HTTP::query] ne "" }{ set myQuery "?[HTTP::query]" } else { set myQuery "" } your condition goes here HTTP::respond 302 Location "https://webname.com/bbb/default.aspx$myQuery"
- Basil_Parsley_1Nimbostratus
Thanks - the more simplex answer met my requirements, and worked ; appreciated the detail.
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