Forum Discussion

Domai's avatar
Domai
Icon for Altostratus rankAltostratus
Sep 27, 2017

iRule help to retain URI and update hostname

Hello Guys, I am trying to come up with an irule to accomplish the following.

http://oldjunk.com/cat/site/default.asp and http://oldjunk.com/cat should be redirected to new page called

But the catch is if a user bookmarked the the old site url with the uri for example

http://oldjunk.com/cat/mmm/cwp/view.asp?a=3483&Q=413540&dcfNav=

it should replace host name and retain the uri

http://oldjunk.com/cat/mmm/cwp/view.asp?a=3483&Q=413540&dcfNav=

with

This is what I came up with so far -

when HTTP_REQUEST {  
    if { ([string tolower [HTTP::host]] eq "oldjunk.com") and ([string tolower [HTTP::uri]] eq "/cat") } {
        HTTP::redirect "http://newupdatedsite/cat"
    }
elseif { ([string tolower [HTTP::host]] eq "oldjunk.com") and ([string tolower [HTTP::uri]] eq "/cat/site/default.asp") } {
                HTTP::redirect "http://newupdatedsite/cat"    
                }
}

I am not able to understand how I can get the second part in. I would appreciate any elegant approach suggestions or examples.

1 Reply

  • P_K's avatar
    P_K
    Icon for Altostratus rankAltostratus

    Did you try replacing the hostname in the header like below ??

     

    when HTTP_REQUEST {

     

    if { ([string tolower [HTTP::host]] eq "oldjunk.com") and ([string tolower [HTTP::uri]] starts_with "/cat") } {

     

    HTTP::header replace Host "newupdatedsite.com"

     

    }

     

    }