Forum Discussion

rdessert_76127's avatar
rdessert_76127
Icon for Nimbostratus rankNimbostratus
Aug 28, 2013

Strange Behavior With Maintenance Page Redirect iRule

Hello,

 

I've been asked to redirect several websites, all of which are subdomains of a domain (ie. x.site.com, y.site.com, and z.site.com), to a maintenance page when we perform maintenance in the future. All of the sites need to be directed to the same maintenance page so I thought I could create 1 iRule and apply it to the different virtual servers for each subdomain.

 

I created the following rule:

 

when HTTP_REQUEST { set host [HTTP::host] if {$host contains ".site.com"}{ HTTP::respond 302 Location "www.site.com/c/site-down/site-down.php" } }

 

I applied the rule to a test virtual server and tested it and am seeing strange behavior.

 

Firefox throw's the following error:

 

The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

 

This is what is showing up as the redirected URL, a long string of repeated domain name/path. http://x.site.com/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/www.site.com/c/site-down/site-down.php

 

The iRule appears to be pretty straightforward and I'm not sure what is causing this behavior. Am I doing something wrong?

 

Please help!

 

Thanks,

 

Rich

 

1 Reply

  • A couple of problems.

    1) You are not adding the protocol in the Location header so the browser is thinking it's a relative link and thus appending it to the new URL.

    2) If your iRule is on www.site.com, the redirect is going back through the iRule which is then issuing another redirect - thus the firefox infinite loop error.

    You might try something like this

    when HTTP_REQUEST {
       Check host for potential redirect
      if { [HTTP::host] contains ".site.com" } {
         Avoid recursive redirects
        if { ! ([HTTP::uri] ends_with "/site-down.php") } {
           HTTP::redirect does a 302 redirect for you.
          HTTP::redirect "http://www.site.com/c/site-down/site-down.php"
        }
      }
    }
    

    Hope this helps...

    -Joe