Consider this post just a quick note to myself, because I will surely need this again in the future.
Scenario: i have a production server and a development server. As you can easily guess, on the production server i have the live version of the websites and on the development server I develop new features/bug fixes/new websites.
What I usually do is to create a specific subdomain for the development. Sometimes i add that hostname as DNS record, sometimes i just add it to my hosts file. Either way, it’s still possible for others to find your “hidden” development website (for example, Alexa.com displays the subdomains getting traffic, so if you use the Alexa toolbar – not necessarily the official – you will see your development website listed under your domain statistics on Alexa.com).
The solution to the problem is extremely simple: just redirect to the production website the traffic coming from any IP address but yours. Just add to the .htaccess of the development website these lines:
RewriteEngine On
# If it’s not your IP address
RewriteCond %{REMOTE_ADDR} !^1.2.3.4$
# Redirect everything to production host.
RewriteRule ^(.*)$ http://www.stefanogorgoni.com/$1 [R=301,L]
Change of course that 1.2.3.4 to your IP address (if you have a dynamic IP, don’t forget to change the .htaccess accordingly every time the IP changes), and the hostname of destination (the www.stefanogorgoni.com part).
Alistair Lattimore says
Stephano,
I find another practical way of achieving the same outcome is configuring your testing website to require authentication. In this scenario, you can easily give the test website to other people for review without worrying about the IP addresses changing and search engines can’t crawl it either – win win!
Cheers,
Al
stefano says
oh yes, if you have to show the website to someone else, authentication is definitely a better choice. thanks for pointing it out 🙂
if you don’t have to show it though, my option won’t even let others (humans or search engines) there’s a website there.