exceptionhttp-redirectconstruction

My desire: to continue to edit a redirected page


I'm building my first website from scratch and want to redirect all viewers (mainly the employer for appearances sake) to an "under construction" page. I used the following code in the head:

<meta charset="UTF-8">
    <meta http-equiv="refresh" content="1;url=http://example.com">
    <script type="text/javascript">
        window.location.href = "http://example.com"

The problem is, it's a universal redirect..When I adjust the html/css and click to see it, whether in my browser or even just clicking the file to preview, it redirects me to the example (I used youtube as a test).

Is there a way that I can redirect all visitors except myself so I can watch my progress live?


Solution

  • I would filter by the the user's IP address.

    Getting IP with Javascript seems to be a bit tricky. If you can, try putting in a few lines of PHP at the top of the file.

    <?php
        if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '123.123.123.123')))
        {
            header('Location: http://www.youtube.com');
            exit;
        }
    ?>
    

    The 127.0.0.1 IP address is the 'localhost' one for your personal server on your computer. Find out what your public IP is and enter that into the array, after that.

    This is a similar question to this. Thanks to user xdazz for the answer.