Print Reseller Scheme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

htaccess redirect to same domain

Discussion in 'Website Design Forum:' started by philjohns, Feb 17, 2011.

  1. philjohns

    philjohns Senior Member

    Hi everyone,

    Im developing a new wordpress site in the main directory of the domain. I want to redirect everyone but my IP address to an under construction type page that is on the same domain but in the directory /under-construction/index.html

    How can I do this with a .htaccess redirect? Is it even possible?

  2. Code:
    Options +FollowSymlinksRewriteEngine onRewriteCond %{REMOTE_HOST} !^123\.45\.67\.89RewriteRule \.html$ /under-construction/index.html [R=307,L]
    Replace with your IP address (with the periods escaped with a back-slash).

    Another way is to do it within the index.php file. Simply place this at the top:

    <?phpif ($_SERVER['REMOTE_HOST'] != '') {    header('HTTP/1.1 307 Temporary Redirect');    include_once('under-construction/index.html');    exit;}// rest of file
    This will simply include your HTML file unless the IP address is the one specified (you do not need to escape periods this time).
  3. Sunburn

    Sunburn Active Member

    Hi Phill try this....

    Thinks MCB is a better solution - removed suggestion.
  4. philjohns

    philjohns Senior Member

    Thanks for the replies.

    My .htaccess file now reads:

    # Switch rewrite engine off in case this was installed under HostPay.RewriteEngine OnSetEnv DEFAULT_PHP_VERSION 5DirectoryIndex index.cgi index.php# BEGIN WordPress# END WordPressOptions +FollowSymlinksRewriteEngine onRewriteCond %{REMOTE_HOST} !^12\.34\.123\.456RewriteRule \.html$ /under-construction/index.php [R=307,L]
    EDIT: have changed my ip address for random numbers!

    Ive viewed the website on my phone (College Alumni Network | Just another WordPress site) and still get the wordpress site rather than my under construction page...

Share This Page