Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Apr 18, 2012

Rewrite - is this efficient?

I am trying to rewrite just the domain name itself, while leaving the URI intact. This iRule works, however I am wondering if this is the most efficient way to do this?

 

 

I'd like to catch both www.olddomain.com and olddomain .com, and rewrite to newdomain.com while keeping the URI present. This should serve as a wildcard catch-all to cover with and without the www.

 

 

 

www.olddomain.com/path/here.aspx to newdomain.com/path/here.aspx

 

 

 

This is what I came up with, simple enough?

 

 

 

 

 

iRule to intercept olddomain.com and www.olddomain .com

 

Rewrites domain name only, appends URI

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] contains "olddomain" } {

 

HTTP::redirect "http://newdomain.com[HTTP::uri]"

 

}

 

}

 

 

4 Replies

  • what about httpclass?

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       destination 172.28.19.79:80
       ip protocol 6
       httpclass myhttpclass
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b profile myhttpclass list
    profile httpclass myhttpclass {
       defaults from httpclass
       pool none
       redirect "http://newdomain.com[HTTP::uri]"
       hosts {
          "olddomain.com"
          "www.olddomain.com"
       }
    }
    
    [root@ve1023:Active] config  curl -I http://olddomain.com/something
    HTTP/1.0 302 Found
    Location: http://newdomain.com/something
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://www.olddomain.com/something
    HTTP/1.0 302 Found
    Location: http://newdomain.com/something
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Interesting....I will see how this one works - Thank you very much for your help. Is using an httpclass going to be more efficient than the if statement above? I'll let you know how it works

     

     

    EDIT: Works great! However I have another iRule that matches a custom URI and redirects only if client traffic goes to:

     

     

     

    http://newdomain.com/productinfo and http://newdomain.com/productinfo/

     

     

     

    I wonder if this will trigger and log the error "too many redirects"

     

     

     

    I will experiment.

     

  • Is using an httpclass going to be more efficient than the if statement above?it is just my thought.

     

     

    anyway, there is past discussion topic about this.

     

     

    iRule vs HttpClass

     

    https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1182490/showtab/groupforums/Default.aspx