Forum Discussion

Basil_Parsley_1's avatar
Basil_Parsley_1
Icon for Nimbostratus rankNimbostratus
Aug 22, 2016
Solved

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

    ?[HTTP::query]
    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::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"
    

4 Replies

  • Append

    ?[HTTP::query]
    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::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_1's avatar
      Basil_Parsley_1
      Icon for Nimbostratus rankNimbostratus

      Thanks - the more simplex answer met my requirements, and worked ; appreciated the detail.

       

  • Append

    ?[HTTP::query]
    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::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_1's avatar
      Basil_Parsley_1
      Icon for Nimbostratus rankNimbostratus

      Thanks - the more simplex answer met my requirements, and worked ; appreciated the detail.