How to disable public access to a website during maintanace mode

There are times when you want to make changes to your website and you do not want your visitors to see the site before you have finished deploying and testing the website. But your Developers and QA’s might need to visit the website before it goes live. So, in this article I will show you how to achieve this with a simple htaccess file. The htaccess file will enable cookies so that whoever knows the secrete cookies code they will able to see the website other wise all visitors will redirect to the maintenance page of your website.

Note: mod_rewrite module should be enabled in the Apache configuration to complete the task. Modify the domain name and Cookies secret as per your requirement.

Create a htaccess file in the root directory of your application.

Append the below code to the htaccess file.

Usage:

Now whenever you will put a file named “maintenance.txt” in the application root it will redirect all the users to maintenance folder, except those pass the cookies secrete with the URL.

Example: http://www.linuxfunda.com/?PASS=Confidencial

You have to distribute the cookie secrete to your Developers and QA’s to access the website.

Remove the “maintenance.txt” file when you complete your deployment and testing to allow all visitors to access the website. Have fun!!

The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

2 thoughts on “How to disable public access to a website during maintanace mode

    • Hi Vivek,

      It’s very simple.. During our website maintenance we can’t allow our visitor’s to our site right? So, during that period we need to put a maintenance page for our website. But, if we put the maintenance page then how can our tester’s will test the functionality of the site with the new code in the real environment? So, for this the .htaccess file will help you. You can set secrete password in the file. Anybody, who knows the secrete can browse the site during maintenance but other will redirect to the maintenance page. Also It will reduce our work load to put a maintenance page for a website. Just put a file inside the root directory to set maintenance and remove the file to make the site visible for all. Please let me know if you still have any doubts.

      Thanks,
      -Tapas

Leave a Reply