English 中文(简体)
Apache: Deploying a new site to the server
原标题:

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?

问题回答

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_other_page.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.

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.

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;
}




相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签