Redirecting visitors to an Under Construction page

When working on your website, you may want to prevent any visitor from accessing your site except you. This can be done by creating a 302 temporary redirect in your .htaccess file to a construction page. By creating a redirect for any IP address except your own in your .htaccess, you can prevent visitors from accessing your site while you update it. This tutorial will explain how to create a redirect for all IP addresses, except your IP, to a construction page on your server.

Important! You will need to create a page in your public_html called “construction.html“. For information on how to create a page in your public_html see our article on Creating an Under Construction or Coming Soon page.

Steps to allow only one IP access

  1. First, you will need to obtain your IP address. Visit the following link to obtain your IP.

    support.inmotionhosting.com/ipcheck.php

  2. Next, Login into your cPanel
  3. Go to the File Manager. Select the public_html web root.

    Important! Make sure you have the show hidden files box checked.

    Click Go.


  4. Edit the .htaccess file with the code editor.
  5. Code view of htaccess redirect

    Paste the following code at the top of the .htaccess file.

    NOTE! The following code is for IP 123.45.67.89 (The code looks like !^123.45.67.89$). You will want to change the code to your IP.


    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} !^123.45.67.89$
    RewriteCond %{REQUEST_URI} !construction.html
    RewriteRule ^(.*)$ /construction.html [R=302,L]

    Save the file.

    Important! If you are pointing to a subdomain you will need to place RewriteEngine Off code in the .htaccess of the subdomains directory.

    Now when your site is visited, any visitor that is not from 123.45.67.89 will be redirected to the construction.php.

    Important! If you cannot access your website after a certain amount of time, its possible your IP address changed at your local connection. This is common with dynamic IP addresses. You can get your IP again and edit the .htaccess to reflect your new IP address to restore you access to your web site.


6 Comments

  • Will this work with a prestashop install on the main directory and a “coming soon” page on a subdirectory?  I’d like to install prestashop very soon but would rather not have to install it locally, configure it, then upload to the server.  

    • Hello Woodjeweler,

      This should work the same, just put the correct page in on the part below:

      RewriteRule ^(.*)$ /subfolder/construction.html [R=302,L]

      Best Regards,
      TJ Edens

  • Not showing images for me… 🙂

    Must replace line 4 with: 

    RewriteCond %{REQUEST_URI} !(\.(gif|jpg|css)$|^/under-construction\.html$)

    thank you. 

Was this article helpful? Let us know!