Forum Discussion

mski_151743's avatar
mski_151743
Icon for Nimbostratus rankNimbostratus
Apr 23, 2014

URI iRule Redirect Question

Hello,

 

I have the below customer request. I was wondering if the below iRule would handle the request properly. If it looks good I'll try it out on Monday. If you have any suggestions, please feel free to make them. I'm just getting into using iRule URI redirects. I have done a few URL redirects successfully.

 

Customer Request: Redirect www.website.com/points to points.website.com along with all query parameters.

 

MY NOTE: The query parameters they speak of should contain POINTS, or another I'll call, ABCD in the URI. Are these case sensitive in the iRule? I created the below proposed iRule for this request.

 

when HTTP_REQUEST { set uri [HTTP::uri] if { ($uri contains "points")} then { HTTP::respond 301 Location "https://points.website.com/"} elseif { ($uri contains "abcd")} then { HTTP::respond 301 Location "https://points.website.com/"}}

 

9 Replies

  • Try this one:

    when HTTP_REQUEST { 
     if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd") }  { 
      HTTP::respond 301 Location "https://points.website.com/" 
      } 
     }
    
  • I think mski wanted to maintain the query portion of the request too;

    when HTTP_REQUEST {
     if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd") }  { 
      HTTP::redirect "https://points.website.com/[HTTP::query]"
      } 
    }
    
  • This should do you, as HTTP::uri contains the query portion as well:

    when HTTP_REQUEST {
     if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd") }  { 
      HTTP::redirect "https://points.website.com/[HTTP::uri]"
      } 
    }
    
    • mski_151743's avatar
      mski_151743
      Icon for Nimbostratus rankNimbostratus
      Thanks! That seems to be working from my perspective. I will have the customer test tomorrow to verify. It may take a few days, but I'll report back with the results. I really appreciate it!
  • shouldn't it be HTTP::query in HTTP::redirect (rather than HTTP::uri)?

    HTTP::query

    https://devcentral.f5.com/wiki/iRules.http__query.ashx

    e.g.

    [root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd" } {
        HTTP::redirect "https://points.website.com/?[HTTP::query]"
      }
    }
    }
    
    [root@ve11a:Active:In Sync] config  curl -I http://www.website.com/points?icid=ABCD_PROMO_POINTS
    HTTP/1.0 302 Found
    Location: https://points.website.com/?icid=ABCD_PROMO_POINTS
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
    • mski_151743's avatar
      mski_151743
      Icon for Nimbostratus rankNimbostratus
      I was able to use all the iRule suggestions to come up with the below iRule to get the query redirect working. The customer is satisfied. I'm happy it works and happy that I learned a bit more about this type of iRule. Thanks again! when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" } { HTTP::redirect "https://points.website.com?[HTTP::query]" } }
  • shouldn't it be HTTP::query in HTTP::redirect (rather than HTTP::uri)?

    HTTP::query

    https://devcentral.f5.com/wiki/iRules.http__query.ashx

    e.g.

    [root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [string tolower [HTTP::uri]] contains "points" or [string tolower [HTTP::uri]] contains "abcd" } {
        HTTP::redirect "https://points.website.com/?[HTTP::query]"
      }
    }
    }
    
    [root@ve11a:Active:In Sync] config  curl -I http://www.website.com/points?icid=ABCD_PROMO_POINTS
    HTTP/1.0 302 Found
    Location: https://points.website.com/?icid=ABCD_PROMO_POINTS
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
    • mski_151743's avatar
      mski_151743
      Icon for Nimbostratus rankNimbostratus
      I was able to use all the iRule suggestions to come up with the below iRule to get the query redirect working. The customer is satisfied. I'm happy it works and happy that I learned a bit more about this type of iRule. Thanks again! when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "points" } { HTTP::redirect "https://points.website.com?[HTTP::query]" } }