views:

50

answers:

3

I have a site currently live on a domain. I would like to switch it to a new site, that is currently in a password protected sub directory on this server.

I have a "Site Maintenance in Progress" page. I want to set Apache so it displays that by default instead of "index.php". Also, I'd like everything else on the server to be password protected while I make the switch (although that's not essential, I guess).

I added this to the .htaccess file in public_html:

DirectoryIndex siteDown.php

Unfortunately, this doesn't do anything. I can navigate to http://www.example.com/siteDown.php just fine.

I'm on a shared hosting setup. Could that be a problem?

+1  A: 

Shared hosts, typically have a control panel of some sort, that allows you to turn on .htaccess processing.

You should use mod_rewrite rules, as Directory Index will only process entries that end up as

http://www.example.com/

http://www.example.com/this%5Fother%5Fpage.html will still process fine, even though you may have modified DirectoryIndex.

In addition, you really should serve a 503 error, as crawling bots, caches, and other entities may attempt to cache that page as "being" your site.

Daniel
how to serve a 503 error?
Rosarch
http://php.net/manual/en/function.header.php (see last arg )
Daniel
A: 

Some shared hosts don't permit .htaccess. Check your hosting's TOS to see if they are allowed, or put some "garbage" (like "asdasdasd") in your .htaccess. If your page loads fine, then the server isn't reading them. If you get a internal server error (500) it's activated.

If you don't have .htaccess enabled, you can do a redirect using php. In the first lines of your index.php:

header("Location: http://domain.com/siteDown.php");
exit();

It isn't the best solution out there, but it works as intended. And if your website structure is always based in index.php querystrings (like index.php?page=home) it works in all pages.

GmonC
A: 

Why don't you add something to the head of your index.php page like:

if($site_down == TRUE)
{
    print "My site is down";
}

Then store your variable in the best place for your situation, such as a database or flat file. If you put this flag into your database you can even set up things like scheduled maintenance and helpful messages to be displayed. This will work on any hosted account with MySQL and PHP and is great when you need to shut down. You don't have to move any files.

The following is very rough pseudocode so don't copy and paste, but this will show you the idea:

$sql = "SELECT * FROM site_maintenance WHERE down_start >= NOW() AND down_end <= NOW() ORDER BY down_start ASC, down_end ASC LIMIT 1;";
// GET YOUR RESULT SET 
if( COUNT($result) == 1 )
{
    print "Site Down: {$row->reason}";
    exit;
}
angryCodeMonkey