Forum Discussion

jirish5563_3502's avatar
jirish5563_3502
Icon for Nimbostratus rankNimbostratus
Jan 30, 2018

Rewrite URL (301) when matches a certain condition

I want to forward traffic from my old site to my new one. They are not in the same data center so this might make it a bit more challenging.

 

DNS is going to be updated so that "; will get sent to the IP address for ";, when the traffic gets there I want it to meet with my iRule to rewrite the URL.

 

Presently I have tried something like this: when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "abc.def.com" { HTTP::respond 301 Location "https://zyx.wvu.com[HTTP::uri]" } }

 

I need this configured in such a way so as to preserve any of the trailing arguments. So if there is a "/something/landingpage.aspx" after the ".com" it needs to remain there, but the domain needs to be updated so that the URL will match and not cause the certificate to blow up.

 

What I have above does not appear to work, though I have tried to narrow down the rule as much as possible.

 

Any ideas would be appreciated as I am very new to F5 configuration.

 

4 Replies

  • Can you please open up Firefox debugger with F12, go to Network tab, and then visit "; ?

     

    Then paste all request and response headers:

     

    • initial request and response headers

    and if it's there,

     

    • request headers to final destination, ";
  • I was able to figure out part of the issue. The reason the iRule was not working was caused by the SSL Certificate. One site would have to redirect to the other and then the 301 can rewrite the URL. Because both of the Certs don't live on the F5 that was at least part of the issue.

    The Rule that I setup, and is working, looks like this:

    when HTTP_REQUEST {
    if {[string tolower [HTTP::host]] equals "abc.def.com"}
            {
            HTTP::redirect "https://zyx.wuv.com[HTTP::uri]"
        }
    }
    
    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus

      Sweet. FYI,

      HTTP:redirect
      function only does 302 redirects. For 301, you must use
      HTTP::respond 301 Location "foo"