How to put a site into maintenance mode while still allowing only me to access?

1.3k views Asked by At

I am about to upgrade my whole site and I am looking for a way to do the maintenance process, but still allowing me to access.

I am thinking of using htaccess. However, that only redirects users accessing for example, index.php to maintenance.php, right? If a user accesses dashboard.php, there will be no redirection.

During the maintenance, I do need to access index.php (ONLY ME).

2

There are 2 answers

0
aurora On BEST ANSWER

We are using LightTPD as web server and i am using "mod_magnet" to do such things. Mod_magnet allows me to do request handling using simple lua scripts. We have an automatic task, which will create an empty file somewhere in the web-server's filesystem. The lua script will check for existance of this file on every request and return a static maintenance page, if the file is found. The important part of the script looks like the following:

--
-- maintenance page
--
local config = {
    ['maintenance'] = {
        ['allow'] = {
            '127.0.0.1'    -- just an example IP address
        }
    }
}

if lighty.stat(lighty.env['physical.doc-root'] .. 'maintenance') then
    tmp, _ = table.search(config.maintenance.allow, lighty.env['request.remote-ip'])
    if not tmp then
        -- maintenance modus
        lighty.content = {
            { filename = lighty.env['physical.doc-root'] .. 'error/maintenance.html' }
        }

        return 503
    end
end

In the script there's also a configuration to still let specific IP addresses through, so you can still view the website for example from your company network, when everyone else just get's the maintenance page.

This solution works very well and because of automation, it does not matter, if you need the maintenance page on one or on many webservers.

If you are interested, you can find more information regarding "mod_magnet" over here:

http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModMagnet

0
J Cobb On

Since you mention .htaccess I'm assuming you're using Apache as your web server. As other have mentioned you can use .htaccess or you can edit the VirtualHost conf for that specific site.

Either way I would recommend using mod_rewrite as Jonathon Sampson recommended, however, you want to be very careful to make sure that you send the proper status codes as well because important bots such as GoogleBot want to see a 503 which tells them that you are currently in maintenance.

There are some pretty clear instructions for doing exactly what you want in this AskApache article.