Forum Discussion

MMaaroufi's avatar
MMaaroufi
Icon for Nimbostratus rankNimbostratus
Jul 02, 2019

URL redirect

Hi everyone,

 

I need to create an iRule that can manage these modification:

 

  • HOST “abc-ppi” ==> “abc”
  • Modify URI "/a/b/c" ==> "/a/b/c-ppi"
  • NOT modifying any other URI

 

Any suggestion please ?

  • Very explicit but this what you need?

    event HTTP_REQUEST {
      if {[string tolower [getfield [HTTP::host] ":" 1]] eq "abc-ppi"} {
          HTTP::header replace "Host" "abc"
      }
      if {[string tolower [HTTP::uri]] eq "/a/b/c"} {
          HTTP::uri "/a/b/c-ppi"
      }
    }
  • Very explicit but this what you need?

    event HTTP_REQUEST {
      if {[string tolower [getfield [HTTP::host] ":" 1]] eq "abc-ppi"} {
          HTTP::header replace "Host" "abc"
      }
      if {[string tolower [HTTP::uri]] eq "/a/b/c"} {
          HTTP::uri "/a/b/c-ppi"
      }
    }
  • Hello Andy,

    Thank you for your reply, i'll test it and let you know if it worked.

    Regards.

  • Try this (untested)

    when HTTP_REQUEST {
        set cField [getfield [HTTP::uri] / 4]
        set newHost [string map {"-ppi" ""}[HTTP::host]]
        set newUri [string map [list $cField ${cField}-ppi] [HTTP::uri]]
        HTTP::redirect https://$newHost$newUri
    }
  • Hello guys,

    I simply did this and it worked just fine.

     

    when HTTP_REQUEST {

     if { [HTTP::host] eq "abc-ppi"} {

       HTTP::header replace "Host" "abc"

     }

     if {[HTTP::uri] eq "/a/b/c"} {

       HTTP::uri "/a/b/c-ppi"

     }

    }

    Thanks again for your help.