Forum Moderators: phranque

Message Too Old, No Replies

Site Under Construction

         

username

4:06 am on Sep 25, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi, I am looking for a command to temporarily set via a .htaccess file, my site to being under construction. Does a commmand like this exist? Is it possible to set an entire domain under construction this way?

tangor

5:14 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use .htaccess to deny any, except your development ip.

g1smd

6:46 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should keep your real site off-line for the minimum possible time if you are swapping designs.

If it is a brand new site, build a minisite to at least show people who you are and what you will be doing, and get that indexed, while you test the real site in a password protected dev subdomain.

The correct response for a site that is offline is to return '503'.

Content returning 200 will be indexed.

4xx error messages are usually not a good idea in this context.

username

8:11 am on Sep 25, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



ok, so what is the command to have all visitors during a period of temporary maintenance see the 503 page? I tried the below, but it had no affect from my root .htaccess?

ErrorDocument 503 /error_503/index.php

Thanks in advance.

Caterham

9:37 am on Sep 25, 2009 (gmt 0)

10+ Year Member



what is the command to have all visitors during a period of temporary maintenance see the 503 page?


ErrorDocument 503 /error_503/index.php
RedirectMatch 503 ^(?!/error_503/index\.php)

username

9:58 am on Sep 26, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



No, unfortunately this causes a 500 internal server error? It should work like a custom 404 page I thought, showing the page at /error_503/index.php?

Any ideas?

jdMorgan

12:57 pm on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What version of Apache server are you hosted on?

When you get the 500-Server Error, what do you see in the server error log?

Jim

username

8:24 pm on Sep 26, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



I am running Apache 1.3.41 (Unix), couldn't find anything in the logs though?

jdMorgan

8:44 pm on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You won't be able to use the method above with Apache 1.3.x -- The method requires PCRE and most Apache 1.3.x servers use POSIX regular expressions... :(

So, the challenge here is to find a way to return 503-Unavailable for any request except for your custom 503 error page... Probably using <FilesMatch>, and possibly requiring you to rename your error page (and any files it includes) to have a unique filetype. This would be a bit easier if it was a static page instead of using php, but I'll have to think about it...

Jim

leadegroot

10:57 pm on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about
* use .htaccess to redirect all calls except from your ip to temp.php
* temp.php throws a header of 503 and shows a pretty 'we're coming!' page?

.htaccess:


RewriteCond %{REMOTE_ADDR} ^123\.123\.123\.123
RewriteRule .* /temp.php [L]

temp.php:

<?php @header("HTTP/1.1 503 Service Temporarily Unavailable"); ?>
<!DOCTYPE HTML ...

(completely untested, but you get the idea)

Not elegant, but simple and should work no matter what version of anything you are running.

g1smd

11:09 pm on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



use .htaccess to redirect all calls except from your ip to temp.php

This however means that the requested URL does not return the correct 503 response.

Instead it returns a 301 response, and then only after the client has made a new request for a different URL, does the client get the required 503 response.

That situation does not allow the server to directly return a 503 response for the originally requested URL, and the method is therefore flawed.

jdMorgan

1:04 am on Sep 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looking at the code, the "flaw" is only one of terminology, since the code implements an internal rewrite, not an external redirect.

However, a real problem, if this code is to go into .htaccess, is that the /temp.php file itself must be excluded from the rewrite rule (using a negative pattern in a RewriteCond or in the RewriteRule itself).

Jim

g1smd

3:56 pm on Sep 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oops. Yes, you're right. I saw the word 'redirect' in the text, but didn't check for [R=301,L] in the code. My warning stands for any other reader that did the same thing. :)

Caterham

7:13 pm on Sep 27, 2009 (gmt 0)

10+ Year Member



I am running Apache 1.3.41 (Unix), couldn't find anything in the logs though?

Feature development for apache 1.3 stopped several years ago. Of course, you can still use it as you can still run windows 2000 but if you'd like to use new features (Redirect <anystatus> is a new feature since version 2.2) instead of reinventing the wheel, you should consider to upgrade.

username

8:25 am on Sep 29, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



If I was to upgrade to 2.2, does version 2.2 still hold all the same features as 1.3 plus the new ones? Also, if not possible to upgrade (server host may not agree), what alternatives do I have with the 503 issue?

Caterham

1:30 pm on Sep 29, 2009 (gmt 0)

10+ Year Member



If you have a good host, your host has several servers running different version combinations of server software (apache/mySQL/php etc.) where you can chose what you want and they'll move everything automatically to the new server.

Upgrading issues are addressed at

[httpd.apache.org...]
[httpd.apache.org...]

what alternatives do I have with the 503 issue?

The script solution with perl/PHP and mod_rewrite as addressed above.

jd01

2:37 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I am looking for a command to temporarily set via a .htaccess file, my site to being under construction. Does a commmand like this exist? Is it possible to set an entire domain under construction this way?

Yes. The following seems to be the closest to correct so far:

How about
* use .htaccess to redirect all calls except from your ip to temp.php
* temp.php throws a header of 503 and shows a pretty 'we're coming!' page?

.htaccess:

RewriteCond %{REMOTE_ADDR} ^123\.123\.123\.123
RewriteRule .* /temp.php [L]

temp.php:

<?php @header("HTTP/1.1 503 Service Temporarily Unavailable"); ?>
<!DOCTYPE HTML ...

(completely untested, but you get the idea)

Not elegant, but simple and should work no matter what version of anything you are running.

But I don't know why you would redirect (or rewrite) everything, except with a 307 TO the index page, since G-bot is an HTTP/1.1 user-agent and will not cache the redirect to the home page if you do not set an expires or cache-control header, will only cache the redirect for the period of time before it is set to 'expire' and will also continue to request the original location on subsequent visits, rather than requesting the new location.

307 Temporary Redirect

The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.

The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s) , since many pre-HTTP/1.1 user agents do not understand the 307 status. Therefore, the note SHOULD contain the information necessary for a user to repeat the original request on the new URI.

If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

[w3.org...]

If you chose to redirect you could use the FireFox User-Agent Switcher* a bit creatively while you develop 'behind the scenes' and set your user-agent to some unique string EG 'Site_Reconstruction_Team' with the following in Mod_Rewrite in your .htaccess file:

RewriteCond %{HTTP_USER_AGENT} !^Site_Reconstruction_Team$
RewriteRule !^(index\.php)?$ http://www.example.com/ [R=307,L]

The preceding will redirect any user-agent, except Site_Reconstruction_Team, *temporarily* to the home page.

You then can put the following at the top of the home page (or all pages if you choose to not redirect) and everything will load the way it should, except you tell SE spiders to not cache any page it resides on and retry after N seconds. (You must set a retry-after header or the request will be handled as a 500, per the documentation. (See Below))

<?php

header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Retry-After: SECONDS");

?>

503 Service Unavailable

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.

[w3.org...]

* You can actually change most browser's user-agent string, but it's easiest with FireFox.

Just my .02 on the situation anyway...

jd01

4:14 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a little note... You could actually combine leadegroot's solution and mine using:

RewriteCond %{HTTP_USER_AGENT} !^Site_Reconstruction_Team$
RewriteRule !^(index\.php)?$ /index.php [L]

/* At the top of index.php */

<?php

header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Retry-After: SECONDS");

?>

But personally, I would opt for redirecting using a 307, rather than rewriting... Even if some might think it's incorrect, because the initial server response is 307, not a 503. It's just what I would do and either solution should work. (I have successfully used 307's before, but your results may vary.) I Do Not recommend using a 301, because it's a permanent redirect and says something different to SEs, but my solution is effectively the same as leadegroot's, except with mine everyone lands on the home page and receives the message, rather than an internal page, and if I have the choice of providing a 'hey were doing something page' when someone clicks on an internal URL I would rather redirect them...

It gives me a really cool opportunity to be a bit creative and I might even add a Query_String to the redirect (or set a cookie when they land), so I know if they came from an internal page and show those people a slightly different page, with something like, 'Hey, we brought you here to our home page while we are building a whole new site for you... The page you tried to visit should be available again shortly. Please bookmark this page where we will be publishing our status reports and updates by clicking here, and bookmark the page you initially tried to visit by clicking here, then check back regularly to see our progress! Here's some of the new features we're working on for you...'

Anyway, that's pretty much the reasoning behind why I would redirect to the home page over just rewriting. But that's just me and my newest sites are AJAX and unspiderable, so I'm half off to start with, but hope it gives you some ideas anyway.

jdMorgan

11:55 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I appreciate cleverness as much as anyone else, but note the the Retry-After header specifies time in seconds, and that should be taken as a clue that 503s should last for hours at most, not days. In most cases, modern users aren't going to read long explanations or bookmark this or that -- They want what they want right now! If your site isn't up, they're going to go right back to their search and click the second search result...

So if the plan is not to have the new site ready by tomorrow noon, then the old site should be left on-line until the new site is ready and has been tested on a separate server. Then switch over all at once, using the 503 (if necessary) only during the time required to duplicate the database from the old site over to the new site.

Jim

jd01

1:26 am on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually I thought the 503 was incorrect based on the documentation, then I read on Google's blog where it's what they said to use, so I thought about it for a bit and if I wanted to serve an 'under construction' page for an entire site the preceding is how I would do it.

Obviously, current traffic is not that important (if there is any), or the OP would not want to take it off line at all, but I would probably try to catch the interest of a couple people and pick up a couple bookmarks, which is way more than would be received with the 'make sure they can run away fast' method, because if you don't at least try to tell them what's going on and they visit a couple times 'your site is always broken'.

Retry-After header specifies time in seconds, and that should be taken as a clue that 503s should last for hours at most, not days

Using the same logic everything on a site should 'expire' within hours at the most too, not days or months, like JS, images, CSS files, etc. correct? (I'm really not sure I'm understanding your logic here, when just about all 'times' are set in seconds, including expires headers, cache-control's max-age, php times, etc. We usually agree, but I'm boggled by your statement on this one.)

Would I personally ever put an entire site 'under construction'? The only reasons I can think of are: if I was building it and started with the home page and added the redirects as pages were added, but inner pages would be unlinked and therefore most likely unused. Or, as far as taking a current site off line and purposely serving a 503 site wide if there is traffic? If I was changing the topic of a low traffic, currently non-monetized website and wanted to try to pick up some of the visitors from the current topic and get them interested in the new one, I might especially if the site was an eye-sore and I had something 'cool' to replace it with.

jdMorgan

5:47 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was just stating (as an opinion) that a 503-Service unavailable is not the kind of thing that you want to leave on a server for more than a very few hours. And also that a "live server" should not be used for development, and that a "new site" should be developed and undergo user-acceptance testing offline in a controlled environment. Since Apache is free and PCs are cheap, it doesn't cost much and you can be sure that no-one (and no thing) will get into your site until it is ready.

It is, however, a good idea to work out how to do a 503 and to have that infrastructure in-place, ready to be 'switched on' if there is any possibility that it might become necessary to do a database restoral, update, or equalization at any time in the future -- that is, the site is dynamic and relies on a database. That's really the only circumstance that I can think of that justifies a 503, because you can't have users changing the database while it is being restored/updated/equalized, and this process might feasibly take a few hours, rather than just seconds.

Jim

jd01

5:54 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it.

Thanks for the clarification. I probably came across a bit terse in my reply, but didn't mean it that way... My apologies. Sometimes I come across shorter than I intend when typing. (It's one of those fault thingies.)