Upgrading a website without sub-domains
Found a great discussion on making upgrading a website or live testing multiple versions of a website whilst the user goes about their business unaware of the changes until "the flick of a switch."
Basically all that is involved is a few simple htaccess redirects with conditional and mod_rewrite rules.
For example I am currently making major updates to http://www.gumauctions.com including a new updated database structure, but I want run live tests as a user would see it including the correct url's but without any interruptions to normal business. A few google searches later and I found an article on WebmasterWorld.
By simply changing the file structure of a website on the server it is easy to show a version to everyone else while I work on the latest update.
How I set my file structure up:
First copy the current website files into a new sub-directory - I called the folder 1.0
Second create a new directory for the new files - Folder name 2.0
Now by using the .htaccess file in the root directory I redirect all my web traffic to the 1.0 folder, while working in the 2.0 folder with the following.
## Switch to version 1.0 ##
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteCond $1 !^1.0/
RewriteRule ^(.*)$ /1.0/$1 [L]
## Switch to version 2.0 ##
RewriteCond $1 !^2.0/
RewriteRule ^(.*)$ /2.0/$1 [L]
Here is a break down of what is happening.
## Switch to version 1.0 ##
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteCond $1 !^1.0/
RewriteRule ^(.*)$ /1.0/$1 [L]
The first line tells the server to check the accessing IP address. IF it doesn't match 127.0.0.1 rewrite the the file directory to show the files in the sub-directory 1.0
## Switch to version 2.0 ##
RewriteCond $1 !^2.0/
RewriteRule ^(.*)$ /2.0/$1 [L]
If my IP address matches the first condition I will be shown the files in 2.0.
When the new version of the site is ready I can now simply remove the 1.0 condition and with no site downtime everything is instantly changed over
So why bother doing this?
- No website downtime
- Seamless changeover to the customer
- No effect on the search engines as the site url's will remain the same
- Changing back to an old version is now possible with a few extra lines in the htaccess file
Points that I considered:
- Any changes to the new sites page structure need permanent redirects in the htaccess file so search engines and users do not get 404 error pages
- When changing over databases or testing with the live db make sure there is a backup. I chose to use separate databases to ensure nothing went wrong with the data being currently viewed.
The post on WebmasterWorld can be found at http://www.webmasterworld.com/apache/3144177.htm