Forum Discussion

Jean_Mamène's avatar
May 29, 2019

Irule redirect all paths /* of my domain

Hello,

 

I will need to set up a redirection for all the paths of my domain name. Example : https://test01.test.com/* => https://test02.test.com

Thank you in advance for your feedback.

 

Regards,

 

5 Replies

  • This is an simple one and has been asked many times on DC, you'll probably find the answer you're looking for by searching the site.

    Eitherway, you can use simple iRule like this:

    when HTTP_REQUEST {
        if {[HTTP::host] equals "test01.test.com"} {
            HTTP::redirect https://test02.test.com[HTTP::uri]
        }
    }

    Otherwise, you can use an Local Traffic Policy, which are better suited for these simple requirements

    https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/local-traffic-policies-getting-started-12-1-0/1.html

    • Lee_Sutcliffe's avatar
      Lee_Sutcliffe
      Icon for Nacreous rankNacreous

      Thanks for the update.

      You'll need to be careful with this one as you risk causing a redirect loop, given you're redirecting to the same location. The following iRule will redirect only if the URI is not equal to the root path. This should stop requests getting stuck in a loop. Make sure you test this in a non production environment first.

      when HTTP_REQUEST {
          if {([HTTP::host] equals "test01.test.com") && !([HTTP::uri] equals "/")} {
              HTTP::redirect https://test01.test.com
          }
      }
  • Thanks for your quick return Lee. Your irules works very well for redirection. However, it changes the HTML display of the site. I do not know where it comes from..

     

    Regards,

     

     

    • Lee_Sutcliffe's avatar
      Lee_Sutcliffe
      Icon for Nacreous rankNacreous

      It will do, if you redirect everything to the default context root (“/“) then any images or CCS files will also get redirected and may not load properly.

       

      perhaps if you describe what you are trying to achieve, I may be able to propose a better solution?