Forum Discussion

Korai's avatar
Korai
Icon for Nimbostratus rankNimbostratus
Mar 01, 2021

Redirect Two URLs to Single URL

Hi,

 

I have a requirement to redirect traffic for two URLs to a single URL by using irule.

 

Suppose traffic for https://abc.com/path1 and for https://xyz.com/path2 should be redirected to https://newsite.com/path3/abc

 

what irule should I use to achieve this.

6 Replies

  • Something like this should do,

    if {(([HTTP::host] eq "abc.com") && ([string tolower [HTTP::uri]] starts_with "/path1")) || (([HTTP::host] eq "xyz.com") && ([string tolower [HTTP::uri]] starts_with "/path2")) } {
    HTTP::redirect https://newsite.com/path3/abc
    }
  • Korai's avatar
    Korai
    Icon for Nimbostratus rankNimbostratus

    Thanks,

     

    Can we make this more simple like because abc.com and xyz.com is same means this part of URL is similar so lets consider this as abc.com for both sites but paths are different and should be redirected to same newsite.com.

  • Hello,

    You can modify above iRule as given below.

    if {(([HTTP::host] eq "abc.com") && (([string tolower [HTTP::uri]] starts_with "/path1") || ([string tolower [HTTP::uri]] starts_with "/path2"))) } {
        HTTP::redirect https://newsite.com/path3/abc
        }

    Hope it helps!

  • Korai's avatar
    Korai
    Icon for Nimbostratus rankNimbostratus

    getting errors, looks format is not right as unable to save it

  • Hi, use below iRule.

    when HTTP_REQUEST {
     
        if {(([HTTP::host] eq "abc.com") && (([string tolower [HTTP::uri]] starts_with "/path1") || ([string tolower [HTTP::uri]] starts_with "/path2"))) } 
        {
            HTTP::redirect https://newsite.com/path3/abc
            }
            
            }
    • Korai's avatar
      Korai
      Icon for Nimbostratus rankNimbostratus

      Thanks It works

       

      Both URLs are directed to single URL and successfully tested