Forum Discussion

Craig_Gibb_1781's avatar
Craig_Gibb_1781
Icon for Nimbostratus rankNimbostratus
Apr 22, 2015

Problem with multiple redirects in irule

Hi anyone suggest how this irule could work better iam having problems with it at the moment too many redirects and the syntax is not that great.

when HTTP_REQUEST { if { [HTTP::uri] contains "/PUTV1-" } { set host [string map {vodrr-stage.site.se stage.site.se} [HTTP::host]] log local0. "Incoming URI = [HTTP::uri]" if { [string tolower [HTTP::uri]] starts_with "/vod" } { set uri [string map {"/vod" "/nPVR"} [HTTP::uri]] log local0. "New URI = $uri" HTTP::uri $uri }

     HTTP::redirect "http://$host[HTTP::uri]"
   } else {
     set host [string map {vodrr-stage.site.se cu.site.se} [HTTP::host]]
     HTTP::redirect "http://$host[HTTP::uri]"
   }
}

/Thanks Craig

2 Replies

  • May you repost your code with the code block delimiters (~~~)?
  • can you try something like this?

    when HTTP_REQUEST { 
      if { [HTTP::uri] contains "/PUTV1-" } { 
        set host [string map {vodrr-stage.site.se stage.site.se} [HTTP::host]] 
        if { [HTTP::uri] starts_with "/vod" } { 
          set uri [string map {"/vod" "/nPVR"} [HTTP::uri]]
          HTTP::redirect "http://$host$uri"
          return
        }
        HTTP::redirect "http://$host[HTTP::uri]"
    
      } else {
        set host [string map {vodrr-stage.site.se cu.site.se} [HTTP::host]]
        HTTP::redirect "http://$host[HTTP::uri]"
      }
    }