Forum Discussion

tsm_329805's avatar
tsm_329805
Icon for Nimbostratus rankNimbostratus
Aug 08, 2017

Irule redirection from old URL (abc.com) to new URL (xyz.com)

All,

 

Looking for irule to redirect when user hits abc.com that should redirect to xyz.com. Note: xyz.com is just a CNAME for abc.com.

 

looking forward for your help.

 

Thanks, TS

 

  • Hi,

    You can use the following irule :

    when HTTP_REQUEST {
        if { [HTTP::host] eq "abc.com" } {
            HTTP::respond 302 noserver Location "http://xyz.com" Connection Close
             alternative : HTTP::redirect "http://xyz.com"
        }
    }
    

    Or you may prefer to use an LTM policy for that.

    Yann

    • tsm_329805's avatar
      tsm_329805
      Icon for Nimbostratus rankNimbostratus

      Thanks for quick reply.

       

      Sorry about my ask, forgot to mention that the requirement is for https. will this below still valid.? //

       

      when HTTP_REQUEST { if { [HTTP::host] eq "abc.com" } { HTTP::redirect "; } }

       

      //

       

      Thanks, TS

       

    • Yann_Desmarest_'s avatar
      Yann_Desmarest_
      Icon for Nacreous rankNacreous

      Yes sure. it's still valid.

      I prefer using

      HTTP::respond
      but you can also use
      HTTP::redirect
      . I prefer the first option because you have more control on the response like removing Server header, Closing connection, etc.

  • Hi,

    You can use the following irule :

    when HTTP_REQUEST {
        if { [HTTP::host] eq "abc.com" } {
            HTTP::respond 302 noserver Location "http://xyz.com" Connection Close
             alternative : HTTP::redirect "http://xyz.com"
        }
    }
    

    Or you may prefer to use an LTM policy for that.

    Yann

    • tsm_329805's avatar
      tsm_329805
      Icon for Nimbostratus rankNimbostratus

      Thanks for quick reply.

       

      Sorry about my ask, forgot to mention that the requirement is for https. will this below still valid.? //

       

      when HTTP_REQUEST { if { [HTTP::host] eq "abc.com" } { HTTP::redirect "; } }

       

      //

       

      Thanks, TS

       

    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus

      Yes sure. it's still valid.

      I prefer using

      HTTP::respond
      but you can also use
      HTTP::redirect
      . I prefer the first option because you have more control on the response like removing Server header, Closing connection, etc.

  • Hello tsm,

    you can also use it to https 😉 add the "string tolower" so you can also redirect hostname with capital letter (example ABC.com).

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] eq "abc.com" } {
            HTTP::respond 302 noserver Location "https://xyz.com" Connection Close
             alternative : HTTP::redirect "https://xyz.com"
        }
    }
    

    Regards