How To Seamlessly Switch Web Hosts
Nov212010
Tags: ColdFusion, Servers, Web Programming
When a server is moved to a different host, if you don't prepare properly, bad things can happen. This is due to the fact that you have to change the DNS Nameservers. When you do this, it takes somewhere between 36 and 72 hours to propagate across the Internet. What this means is that during this time, some web surfers who type in your domain name will end up going to the old site and some will end up going to the new site. If you have a static site that doesn't do anything, this is totally fine, no biggie!
Where a problem can occur is when you have a dynamic database driven website. During the move, you don't want to have some users accessing one database while other users are accessing a different one. This is just asking for problems! Some data will get lost if you don't go into the database and specifically compare and contrast the data.
Imagine that you have a forum and some users are replying to the same thread through two different databases! If you don't prepare beforehand and take the proper actions, afterwards things will be missing. Now imagine if this was an ecommerce website! You will have missed orders and have upset customers. People may have gotten their charge card billed and never received a product!
If you use a server that can support a .htaccess file you can forward all traffic from the old server to the new server by placing the following code in the file.
RewriteCond %{HTTP_HOST} ^yourwebsite\.com$ [NC]
RewriteRule ^(.*)$ http:/theipaddress/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.yourwebsite\.com$ [NC]
RewriteRule ^(.*)$ http://theipaddress.com/$1 [L,R=301]You can also do it programmatically through a scripting language like ColdFusion:
<cfset currenturl="http://theipaddress">
<cfset cgi.path_info="" currenturl="CurrentURL15">
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#currentURL#">
<cfabort>
</cfabort></cfheader></cfheader></cfset></cfset>Another Simple way of going about solving this situation is to have the new server connect to the old database until the dns servers have totally propragated over. Just use the connection string for your old database. After the 36-72 hour time period, move the old database over to your new server (preferably in the middle of the night). If you are on a shared server and using ColdFusion, this option may not work depending upon your host.
There are many ways to solve this problem. The best way to go about solving this problem is based upon your specific web application and server.

Comments
Post new comment