When we develop sites (ideally) we use a development and staging servers and hopefully not directly on the live site.
Development sites are usually not accessible via internet but the staging ones are.

When the site is ready to be posted live the access to the staging site should be blocked.

Why?

Because in case of a (future) troubleshooting we or the client could accidentally visit it, make changes to it and you will have to apply the changes to the live site.

Additionally, browsers remember our browsing history which improves their auto suggest features.
When we are in a rush we don't pay too much attention to the address bar as long we're on the right client site.

If you're using the Apache web server you can paste the block of code below at the begging of the .htaccess file. If the file doesn't exist create it.
Using .htaccess is a better approach than blocking the access using .php because if you have static files (such as .css, .js, .pdf, .docx etc)
the will still continue to be accessible.

[code]
deny from all
ErrorDocument 403 "YYYY-MM-DD: The site was posted live. Please, check http://newsite.com"
[/code]

 

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through an referral link (if any) on our site, we earn a commission.