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 Parked at Loopia

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]”

}

}

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:

Parked at Loopia 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

Thank you, everything is working great with your httpclass.