Forum Discussion

Sean_M__85845's avatar
Sean_M__85845
Icon for Nimbostratus rankNimbostratus
Feb 08, 2012

HTTP::redirect Help

I am looking for some help to create an iRule that will look for a variable that follows "/open/" in the URI and then reuses that variable in the redirect.

 

 

Basically when a user hits the following link:

 

http://www.abc.com/open/42579900

 

 

They will be redirected to the following link:

 

http://www.xyz.com/MigrationID.aspx?migrationID=42579900

 

 

Any ideas?

5 Replies

  • when HTTP_REQUEST {

     

    if { [http::path] contains "/open/" } {

     

    http::redirect location http://www.xyz.com/MigrationID.aspx?migrationID=42579900

     

    }

     

    }
  • Sorry, I guess I wasn't clear with my original post. The number won't be the same every time and since 42579900 is the variable it needs to be referenced as a variable in the redirect, not a static number. Does that make sense?
  • I think this might work:

    when HTTP_REQUEST {
    set id [findstr HTTP::path "/open/" 0 8]
    if { $id != ""  } {
    HTTP::respond 301 location http://www.xyz.com/MigrationID.aspx?migrationID=$id
    }
    }
     
  • [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set id [findstr [HTTP::path] "/open/" 6 end]
       if { $id != ""  } {
          HTTP::respond 301 location http://www.xyz.com/MigrationID.aspx?migrationID=$id
       }
    }
    }
    
    [root@ve1023:Active] config  curl -I http://172.28.19.79/open/42579900
    HTTP/1.0 301 Moved Permanently
    location: http://www.xyz.com/MigrationID.aspx?migrationID=42579900
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Using the set id [findstr [HTTP::path] "/open/" 6 end] and then referencing $id in the redirect worked perfectly! Thank you both for your help - much appreciated!