Forum Discussion

Drew_123833's avatar
Drew_123833
Icon for Nimbostratus rankNimbostratus
Mar 23, 2015

Redirect full website

Hello everyone

 

I'm trying to redirect my website www.company.com to a sorry page. Due to a database maintenance. I did the redirection through an irule. So far so good.

 

The basic irule to redirect the website is:

 

Code 
when HTTP_REQUEST {
HTTP::redirect "http://sorry.mypage.com[HTTP::uri]"

}

 

The redirections works well, the only problem is that everything under a "/" is not redirected and gives an 404 error. For example www.company.com/products will not be redirected. There a lot of them.

 

Is there a way to do a full redirection of everything to this sorry page?

 

Thx

 

5 Replies

  • Perhaps there are other redirect iRules which take precedence over your maintenance redirect? You could try using the priority function and see whether it resolves your issue.

     

    priority 10
    when HTTP_REQUEST {
      if { [HTTP::host] == "www.company.com" } {
        HTTP::respond 302 location "http://sorry.company.com"
        event disable
        TCP::close
      } 
    }
    

     

    Note: The code above would work only if the maintenance page is not served by the same Virtual Server (listener). If the maintenance page is served via the same Virtual Server, you'll have to add a negative condition to avoid a redirect loop:

     

    priority 10
    when HTTP_REQUEST {
      if { (([HTTP::host] == "www.company.com") && not([HTTP::path] == "/maintenance")) } {
        HTTP::respond 302 location "http://www.company.com/maintenance"
        event disable
        TCP::close
      } 
    }
    

     

    Good luck 😉

  • Hi, why do you need the "[HTTP::uri]" in the redirect? The sorry page have any directory structure?
  • Hi Cjunior Did also without the [HTTP::uri], doesn't change anything. Got same 404 for /products. I was thinking that everything will be redirected, but it seems not.
  • Hi Hannes

     

    Thx for your reply. I did put your first suggestion. The main page will redirect as well. But the /products, /etc. doesn't. The page http://sorry.company.com is on another server/place. Normal the local big ip should do this trick to I guess. Or can we put an extra rule to say that everyting after the slash (/), direct also to sorry.company.com?

     

    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      That's not expected. The redirect in the first iRule will trigger regardless of the URI value specified. Only the "www.company.com" string must equal the HTTP Host header. Perhaps your HTTP Host header is something different - does it include a port specification? As per our current solution, a request to http://www.company.com:8080/products will not be redirected to maintenance page, but http://www.company.com/products will be redirected. Can you try the following: I've added a log statement. As you initiate another attempt, take a look at "/var/log/ltm" file to see whether the redirect is triggered or not. priority 10 when HTTP_REQUEST { if { [HTTP::host] == "www.company.com" } { log local0. "[IP::client_addr]: [HTTP::host][HTTP::uri]. Maintenance redirect triggered" HTTP::respond 302 location "http://sorry.company.com" event disable TCP::close } else { log local0. "[IP::client_addr]: [HTTP::host][HTTP::uri]. Maintenance redirect omitted" } }