Redirect and a comparison in one....

Hi…I’m new to iRules and have received a request to do the following in the same iRule:

1 redirect from one domain to another

and look for a query string…and if found append with condition…if not..add the query..

For example:

https://original.domain.com/page.asmx?datatype=data

changes to

https://new.domain.om/page.asmx?datatype=data&cntgrp=Q

or

https://original.domain.com/page.asmx

changes to

https://new.domain.com/page.asmx?cntgrp=Q

Any suggestions on the structure of this iRule…and also any great places to work on irule examples for practice?

Thanks,

Jim

Not sure whether it works. Give it a try:

when HTTP_REQUEST {  
  set newDomain "new.domain.com"  
  set newUri [HTTP::uri]  
    
  if { \  
  not ([HTTP::host] contains $newDomain) && \  
  $newUri contains "/page.asmx"} {  
    
  if {$newUri contains "?"} {  
  append newUri "&"  
  } else {  
  append newUri "?"  
  }  
  append newUri "cntgrp=Q"  
  HTTP::redirect "https://$newDomain$newUri"  
  }  
  }

hwidjaja…

Thanks for the feedback…I’ve done it a different way, but will try this logic later.

Again, thanks for your help!!!

Jim