Welcome to WebmasterWorld Guest from 18.206.168.65

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Proper 503 maintenance page

503

     
4:50 am on Aug 23, 2015 (gmt 0)

Preferred Member

10+ Year Member

joined:May 21, 2004
posts: 385
votes: 5


Long story short, I am thinking about using opcache on a production site. From what I can see, I should be disabling opcache.validate_timestamps which means it will never check for updated versions of the files. With that said, when it comes time to update any of these files you must clear the cache for the change to be picked up.

So, should I decide to use this I think the best route to go is to implement a 'maintenance' page while I upload and clear the cache... and heck, it might be useful down the road for something else as well.

Here is what I came across after doing some searching and reading, but a few things stick out at me right off the bat.

1 - The [R,L] means this is doing a 302 temporary to the page with the 503. Why? Wouldn't it be best to just do [L] straight to the 503?

2 - Every now and then I come across a maintenance page on a site. Most, while still pretty basic, still have some stylization applied and maybe even an image or two so they aren't the typical black text on white page. How would one get around this? Would you have a separate folder for the 503.php, css, images, etc and then exclude the whole folder from your rewrite rule?

Finally, the basic 503.php with the htaccess commented. Opinions on this? How do you handle your maintenance page/header if you do one?

<?php
//#add redirect in htaccess
//Options +Follow SymLinks
//RewriteEngine On
//RewriteBase /
//# Allow access from specific IP
//RewriteCond %{REMOTE_ADDR} !^000\.000\.000\.000
//RewriteCond %{REQUEST_URI} !^/503\.php [NC]
//RewriteRule .*/503.php [R,L]

header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
header("Retry-After: 3600"); //in seconds
//header("Retry-After: Sun, 5 Jan 2012 13:00:00 GMT"); //in gmt
?>

<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8"/>
<title>title</title>
<meta content="description" name="description" />
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>

<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"/>
<link href="/somestyle.css" rel="stylesheet" type="text/css"/>

<link rel="shortcut icon" href="/favicon.ico"/>

</head>

<body>
some message
</body>
</html>
5:59 am on Aug 23, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4206
votes: 265


In response to the first part:
1 - The [R,L] means this is doing a 302 temporary to the page with the 503. Why? Wouldn't it be best to just do [L] straight to the 503?
A 302 temporary is the better choice for a temporary change of the content you're updating. A 301 is for permanent changes.

Can't help much on the rest, I don't set up a custom 503 for anything. In general you can style a 503 or any custom error page by using inline css or an external stylesheet. If you want to use custom error pages, add the designated page name to your htaccess file as in:
ErrorDocument 503 /503.php
using whatever you name your custom page in place of the generic 503.php filename as shown.
3:29 pm on Aug 23, 2015 (gmt 0)

Preferred Member

10+ Year Member

joined:May 21, 2004
posts: 385
votes: 5


I don't think you were following me on the questions exactly.

I realize the difference between a 301 and 302... my question is why would I use a 302 in-between only to go to the 503? The 503 is specifically for a loaded server and/or maintenance and even lets you include a date and or amount of time in the retry-after header in which everything should be back online. The 503 itself is a temporary condition. So what is the point of the 302 here? Why not redirect straight to the 503 header with the 503 page? The recommendation I listed here would be something like any file -> 302 -> 503 and I don't see the point of the 302 in the middle of this.

Regarding the error page... Your response doesn't really apply here. Yeah, that is how you setup a custom error page in htaccess, but we need to temporarily force a 503 for all files which is the whole point of the headers in this 503.php. Once those redirects are in place all files are redirected to it so any external assets (css, images, etc) would have to be excluded from the redirect rule to be used. So unless I am completely wrong in that thought which I don't think so... is the normal process to just exclude a folder from the redirects to hold all the 503 page assets so they can be used on it?
3:41 pm on Aug 23, 2015 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 323
votes: 24


You shouldn't externally redirect to a 503 (Service Unavailable / Under Maintenance) page. Otherwise the user-agent/bot would see a 3xx redirection status before the 503, which really defeats the object.

Wouldn't it be best to just do [L] straight to the 503?


Well, yes, it would be "better" to internally rewrite to the 503.php page instead (ie. no R flag in the RewriteRule) and make sure you set the appropriate 503 (and Retry-After) headers in the page itself.

However, I would have said it is preferable to set the ErrorDocument (as not2easy suggests) and then "redirect" to the 503 page using the R flag again in the RewriteRule. Note that this is NOT an external redirect. External redirects are only triggered for status codes in the 3xx range.


RewriteRule ^ - [R=503,L]


This will result in Apache's 503 ErrorDocument being served. (In fact, I don't think the L flag is even required here. When using a status code outside of the 3xx range, rewriting is stopped anyway.)

2. How would one get around this? Would you have a separate folder ...


Yes, keep your 503 page separate from your main site and keep it basic. In fact, I would go for just a single page and in-line everything - just one resource to think about. You don't want your maintenance page to break!

Depending on how deep "under maintenance" you are, you might not have access to anything from your main site/framework.
4:38 pm on Aug 23, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4206
votes: 265


Because the 503 is sent in the headers, no redirect is seen when the custom page is served if you don't serve the redirect as 302. The 302 lets robots know this is a temporary change.

I addressed only the portions of your questions that I could, so I specifically did not address anything about the creation of your page. I have no clue what files are in what directories on your domain or whether you have everything in one directory. External resources, links to images, scripts and external style sheets should be accessible to the 503.php page. For a limited number of resources used only temporarily you could create a /temp/ directory for them.

Your rewrite is a little confusing, the rule appears have an extra / where it should have a space. Why would you need a [NC] for an automated redirect?

Given what I can understand about what you want to do, I responded with what I was certain about. Hopefully others can be more helpful.
4:42 pm on Aug 23, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4206
votes: 265


whitespace is right about that -
RewriteRule ^ - [R=503,L]

I missed it.
6:09 pm on Aug 23, 2015 (gmt 0)

Preferred Member

10+ Year Member

joined:May 21, 2004
posts: 385
votes: 5


This is not 'my' code. Searching around led me to this solution which is why I questioned all of this in the first place in the OP. There is no directory structure or anything of that nature applicable here (I would obviously have to change to suit my own needs).

So if I am following here, you are recommending :

ErrorDocument 503 /whatevercustom503.php

and using RewriteRule ^ - [R=503,L]


How would I specify the retry-after header then since I would be using Apache? Would manually adding the header into whatevercustom503.php work correctly in this case? If I have to manually add that in my file I might as well manually make the 503 in the first place and skip using Apache's.
6:30 pm on Aug 23, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15507
votes: 752


my question is why would I use a 302 in-between only to go to the 503?

I dunno, why would you? It's not something anyone hereabouts-- or, for that matter, the Apache folks-- would ever recommend.

RewriteRule ^ - [R=503,L]

Yes, that's the syntax. You can replace ^ with .? but that's a matter of individual taste.

Note that the L flag is not technically necessary, though it does no harm. If the number after "R=" is anything outside the 3xx range, an L is implied. But you must also exempt the custom 503 page to avoid an infinite loop. You can do this either by a preliminary rule like
RewriteRule ^whatevercustom503\.php - [L]
-- that is, the same rule you've already got in place to exempt your custom 403 page-- or you can attach a RewriteCond to the rule itself. Making an exemption package is easier, because you can put the rule at the very beginning of all your RewriteRules and then never think about it again.

It's also a judgement call where, exactly, you want to put the rule with the R=503 flag: either at the beginning of all your RewriteRules, or after all access-control rules but before all redirects. It's conceivable that some unwanted robots could go away faster if they get a 503 response instead of a 403. (I don't know whether a 500-class response trumps a 403 in the case of unwanted visitors who are barred by non-mod_rewrite means such as an IP-based lockout. If nobody knows, I may do some experimenting for future reference.) On the other hand you may not want to give them any information beyond the 403 door-slam.