July 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

XML Feeds

Upgrading a website without sub-domains

Permalink 12:22:19 pm Categories: Code & Stuff

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?


  1. No website downtime

  2. Seamless changeover to the customer

  3. No effect on the search engines as the site url's will remain the same

  4. 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

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

This post has 2 feedbacks awaiting moderation...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))