htaccess redirect to same domain

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?

Thanks
 
Code:
Options +FollowSymlinksRewriteEngine onRewriteCond %{REMOTE_HOST} !^123\.45\.67\.89RewriteRule \.html$ /under-construction/index.html [R=307,L]

Replace 123.45.67.89 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:

Code:
<?phpif ($_SERVER['REMOTE_HOST'] != '123.45.67.89') {    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).
 
Thanks for the replies.

My .htaccess file now reads:

Code:
# 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...
 
Back
Top