I was doing a web design project earlier that required me to work on the live domain. I didn’t want any visitors to see what I was doing, so I set up a temporary blog at temp.mydomain.com. All I needed to do then was to redirect all visitors to that domain, but allow me to stay on the main domain of www.mydomain.com, and continue my maintenance.
The solution was simple; I simply created a .htaccess file on my main domain, in the root folder. The htaccess contained the following information:
RewriteEngine on RewriteCond $1 !^http://www.mydomain.com/temp RewriteCond %{REMOTE_HOST} !^12\.345\.678\.901 RewriteRule (.*) http://temp.mydomain.com/$1 [R=301,L]
It really is that simple to redirect all visitors, except you own IP, to a subdomain. The script above does the following:
- Turn on the rewrite engine (no need to do this if it is already on in your htaccess).
- Exclude the folder /temp from my rewrite (this is where the files for my subdomain are stored).
- Exclude the IP address of 12.345.678.901 from my rewrite rule (you can find out your IP address by going to whatismyip).
- I am then telling it to redirect everything (.*) to my subdomain http://temp.mydomain.com.
All you need to do is swap in the addresses for you subdomain files, your IP address, and your subdomain address. Simple as that!
06:18 30/04/2011
Yes,even i too faced same problem and resolved with htaccess file.