Forum Discussion

jcrubaugh45_208's avatar
Jun 23, 2017

im having problems with issuing a 302 with an iRule

Im brand new to iRules. so go easy on me :)..I have a production URL http://environment.company.com/ and I created a data group which contains 4 unique URI paths ...

 

My goal was if traffic comes into the production URL .. and the URI starts_with the paths in my datagroup I wanted to issue a 302 and ask end users browser to come back on a new URL while preserving their URI path.

 

my datagroup consists of :

 

/lorl/

 

/jc.app.settings.svc.webhost/

 

/jc.leader.joe.webhost/

 

/jc.app/settings.svc.webhost/

 

so when a browser hits http://environment.company.com/lorl/ i want them to get a 302 redirecting them to http://new-environment.company.com/lorl

 

this is what i wrote:

 

when HTTP_REQUEST { if { [class match [[string tolower [HTTP::uri]] starts_with DatagroupNAME ]] } { HTTP::respond 302 location "http://new-enviornment.company.com[HTTP::uri]" } }

 

my end user simply gets a connection reset...

 

6 Replies

  • i entered each of these in the group as a string:

     

    /lorl/

     

    /jc.app.settings.svc.webhost/

     

    /jc.leader.joe.webhost/

     

    /jc.app/settings.svc.webhost/

     

  • eben's avatar
    eben
    Icon for Nimbostratus rankNimbostratus

    Try setting the new HTTP::host as a variable. then call it in the redirect. when HTTP_REQUEST { if { [class match [[string tolower [HTTP::uri]] starts_with DatagroupNAME ]] } { HTTP::respond 302 location "http://$[HTTP::uri]" } }

     

    You could also use a Switch [HTTP::uri] to achieve this.

     

    • eben's avatar
      eben
      Icon for Nimbostratus rankNimbostratus

      when HTTP_REQUEST{ switch [HTTP::uri] { "/lorl/"- "/jc.app.settings.svc.webhost/"- "/jc.leader.joe.webhost/"- "/jc.app/settings.svc.webhost/" { HTTP::redirect "http://new.domain.com/[HTTP::uri]"}

       

      }

       

      }

       

  • Try setting the new HTTP::host as a variable. then call it in the redirect. when HTTP_REQUEST { if { [class match [[string tolower [HTTP::uri]] starts_with DatagroupNAME ]] } { HTTP::respond 302 location "http://$[HTTP::uri]" } }

     

    You could also use a Switch [HTTP::uri] to achieve this.

     

    • eben_259100's avatar
      eben_259100
      Icon for Cirrostratus rankCirrostratus

      when HTTP_REQUEST{ switch [HTTP::uri] { "/lorl/"- "/jc.app.settings.svc.webhost/"- "/jc.leader.joe.webhost/"- "/jc.app/settings.svc.webhost/" { HTTP::redirect "http://new.domain.com/[HTTP::uri]"}

       

      }

       

      }