Forum Discussion

wihjani_304830's avatar
wihjani_304830
Icon for Nimbostratus rankNimbostratus
Jan 14, 2019

iFile maintenance page issue with longer paths

Hi all,

We are using ifiles to serve static maintenance page for our web services. Everything works fine when user navigates to "domain.com/", but if the path contains second "/" (domain.com/abc/) then ifile image won't load.

 

when HTTP_REQUEST { 

if {([active_members Pool-X]) < 1} { 

switch [string tolower [HTTP::uri]] { 

"/image.png" { 
HTTP::respond 200 content [ifile get "image.png"] "Content-Type" "image/png" 
} 
default { 
HTTP::respond 200 content [ifile get "maintenance_page"] "Content-Type" "text/html" connection close
event disable
} 
}
}
}

 

What should I do to make this irule work with any path?

Thanks,

Jani

  • Hi Jani,

    I stringly recommend you to not use a 200OK for every response send to your site. It will pretty much hurt your existing SEO ratings...

    Its far more elegant to tell your clients (and also search engines) that the site is currently not available by 407 - Temporary Redirect to a given Maintenante-Page which is then served using a 503 - Service Unavailable status code.

     

    when HTTP_REQUEST {
        if { [active_members Pool-X] < 1 } then { 
            switch -exact -- [HTTP::uri] { 
                "/image.png" { 
                    HTTP::respond 503 content [ifile get "image.png"] "Content-Type" "image/png" 
                } 
                "/maintenance.html" { 
                    HTTP::respond 503 content [ifile get "maintenance_page"] "Content-Type" "text/html" 
                }
                default { 
                    HTTP::respond 407 Location "/maintenance.html"
                } 
            }
        }
    }
    

     

    Note: For further information how to handle Maintenance Pages the right way, please check out https://plus.google.com/+PierreFar/posts/Gas8vjZ5fmB

    Note: To make the image load in your current iRule example, you may review your HTML and make sure the image file is referenced via "/image.png" (absolute to root web) instead of using just "image.png" (relative to the current web folder). I'm pretty much sure this would fix your original iRule and problem...

    Cheers, Kai

     

  • Miguel's avatar
    Miguel
    Icon for Nimbostratus rankNimbostratus

    Just add extra path to the ifile location, one will work on the main page and the other on the path, enter like this:

    1. when HTTP_REQUEST {
    2.  
    3. if {([active_members Pool-X]) < 1} {
    4.  
    5. switch [string tolower [HTTP::uri]] {
    6.  
    7. "/image.png" {
    8. HTTP::respond 200 content [ifile get "image.png"] "Content-Type" "image/png"
    9. }
    10. "/abc/image.png" {
    11. HTTP::respond 200 content [ifile get "image.png"] "Content-Type" "image/png"
    12. }
    13. default {
    14. HTTP::respond 200 content [ifile get "maintenance_page"] "Content-Type" "text/html" connection close
    15. event disable
    16. }
    17. }
    18. }
    19. }