Want to show your appreciation?
Please a cup of tea.

Saturday, October 09, 2010

IIS Web Site Redirect with Announcement Page

It is common that when you have moved your site from one host to another and you want to redirect all the traffic going to old host to be redirect to the new host before the old host is completely unavailable.

This can be easily done with any major web server. For IIS, Microsoft has a page about this and all you need to do is follow the instruction in the section of “to redirect requests to another Web site or directory”.

Redirect requests to another Web site or directory

Sweet, now you type in a URL going to your old site and you automatically landed to the correct page on your new site. But wait, what’s going to happen if one day you have to shutdown the old site completely. Your user’s bookmark and external link from other site will still be pointing to your old site because the redirect was so transparent that they would have never notice the need to correct their bookmark. When the day comes, they’ll suddenly end up with a broken error page.

Redirect all requests to a single file

Yes, we want to put up a page to let our user know about it so they can update their bookmark during the transition period when both old and new site are up and running. Fine, let’s use the method mentioned in the section “to redirect all requests to a single file”. Now our user can see the nicely written notice that the site was moved to a new home. But wait again, what should use do next after reading our notice, they want to go to that particular page on your site! Where should they click?

Redirect requests to a program

Well, according to Microsoft, we still have last option. That is redirecting to a program that is smart enough to tell user about the move and then send the user to the right page!? This sounds like what we wanted but does it really justify to write a binary executable for such a simple task? No, there got to be a simpler and better way!

Redirect to a smart HTML page

The solution is not difficult. We’re going to tweak the “redirect to program” method by creating an html page with Javascript instead of an binary executable. Let’s call the page “move.html”, you can host the move at anywhere, a virtual dir under old site, anywhere in new site, or a third site.

First, configure you old site’s properties to redirect the site to exactly “http://server/move.html?$P&URI=” without quotes. Make sure none of the checkbox options in the redirect to is checked. See the screenshot below:

image

Then create the move.html page with below content:

<html>
<script type="text/javascript">
var hu = window.location.search;
var position = hu.lastIndexOf('&URI=');
var query = hu.substring(0, position);
var path = hu.substring(position+5);
if (query == '?') query = '';
var url = 'http://thenewcoolsite' + path + query;
linkstring = '<a href="' + url + '">' + url + '</a>';
</script>
<title>The Cool Site Moved</title>
<body>
<h1>The Cool Site Moved</h1>
Please always use the <a href="http://thenewcoolsite/">http://thenewcoolsite/</a> 
to access the the cool site.
<p>
You just landed on the old host of the cool site. This host will be taken offline 
soon and you will get an error instead of this page when it happens. Please take
one of the actions below:
<ul>
<li>
If you access from your web browswer's bookmark or faviorate, please update it 
now with the new link below.
<li>
If you clicked on a link from an email, please notify the sender to correct the link.
<li>
If you are brought to this page by an application or another web site, please notiffy
the owner of the application ASAP.
</ul>
<p>
The new link to your request is in below. Please click on the link, it will take you
to the page that you are looking for.
<p>
<script type="text/javascript">document.write(linkstring);</script>
</body>
</html>

Now if user access http://oldcoolsite/somedeeplylinked/pagewithparameter.aspx?p1=abc&p2=789, you should get the page below with messages that you want to give to user, as well as a link to the new site that that the user attempted to access.

image

Limitations and Enhancements

For this to work, your user’s browser must support Javascript. This is the only limitation but can be a serious limitation for some web sites. But the logic in the Javascript can easily moved to server side with an ASP or JSP.

Wednesday, October 06, 2010

Install Snow Leopard on VirtualBox with Core i5 CPU

There are a few good articles explaining how to install Mac OS X on VirtualBox and a lot of people had reported success:

http://www.taranfx.com/install-snow-leopard-virtualbox
http://www.sysprobs.com/mac-os-guest-virtualbox-326-snow-leopard-1064-windows-7-32-bit
http://www.sysprobs.com/install-mac-snow-leopard-1063-oracle-virtualbox-32-apple-intel-pc

But unfortunately, when I try to install on my Lenovo ThinkPad X201 with Core i5 M520 CPU, none of those guide worked. I couldn’t boot up the Mac Installer DVD from the virtual machine. After a number of hours try and error, I finally got to the conclusion that all my failures were because, the boot loader and OS X version combinations that I tried, none of them supports my Core i5 CPU.

I then searched up and down for the support of Core i5 boot loaders. With help from my friend, I found this page. It has no mention of VirtualBox but the tools and instructions worked for me. When I was about to write a full blog of the detail steps, I came to know from Dinesh that he actually had a post about using iBoot with VirtualBox, which was pretty much what I did.

Now you have two options to go. a) Use a pre-built VirtualBox disk image (.vdi) that has both Snow Leopard 10.6.4 and boot loader pre-installed; b) install manually step by step yourself.

Using Pre-built Disk Image

This is an easiest option to go,

  1. Download the the disk image following the links provided in the end of all steps. Total 7.5G compressed and 12G expanded.
  2. Unzip it using 7-Zip, a really cool free utility that can open almost any compressed file including .iso image.
  3. Rename the downloaded vdi file to something reads better to you, say SnowLeopard.vdi and place it in the your virtual disk image folder. You can find your Default Hard Disk Folder in settings of the VirtualBox console (File->Preferences or Ctrl-G)
    image
  4. Complete only the step 1 of the instruction here to create the Virtual Machine, except that do NOT create the hard disk as we already have one, acknowledge to the warning message and continue.
    sn2
  5. Go to setting of the newly create VM and selected the Storage on left. Keep the CD/DVD drive and delete all Virtual Hard Disks if you accidently created in last step. Add a SATA Controller and select the newly downloaded vdi file. Use the folder icon with green arrow to add the disk if it is not already in the Hard Disk dropdown list.
    sn4
  6. Start the VM and have your Mac OS X running, the user id and password are both “vbox”.
  7. To change the screen resolution, follow the instructions in the manual install option.

Snow Leopard 10.6.4 pre-installed bootable VirtualBox disk image download links from fileserve:

Install Using iBoot and Snow Leopard Retail DVD image

Somebody may prefer this option because it allows you customize the installer where you can select if you would install the additional languages and print drivers. I’ll save my time by introducing you to that post for most of it and just noting down things that you need to watch out here.

My Environment

Lenovo ThinkPad X201, Core i5 M520 CPU, 4GB RAM, Integrated Graphics, Windows 7 Ultimate 32bit, VirtualBox 3.2.8

I have Snow Leopard 10.6.3 Install DVD iso image on hand and so that’s what I used. I believe 10.6.4 will sure work and 10.6.2 is the first version supports Core i series CPU so it “should” work too. Anything older than that won’t work, don’t bother trying.

Install Boot Loader to HDD

It is very important that you must update to 10.6.4 before installing the boot loader from MultiBeast package. Otherwise, your Mac won’t boot at all, not even from the iBoot boot loader iso. Always take a snapshot of your VM before you do this.

Screen Resolution

There are three methods described on this page. I tried first one, doesn’t work, than I tried 2nd one, I cannot start VM. So eventually, that’s how I made it work.

  • You need both method 1 and 2, any one along won’t work.
  • You must have the boot loader installed to HDD first, i.e. you must be able to boot directly from HDD.
  • For method 1, you must edit the plist file under /Extra, not the one under /Library/Preferences/SystemConfiguration.
  • The command line described in method 2 will corrupt your machine XML file. I had to edit the file manually. To edit the XML file:
    1. Find the location of the xml file by going to File->Preferences of you VirtualBox console and get the value of Default Machine Folder (see the image above). Go to that folder and see <Your Machine Name> sub folder. The XML file is there.
    2. Shutdown all VM instances and also close VirtualBox console. This is very important as otherwise your change will be overwritten.
    3. Backup <Your Machine Name>.xml file.
    4. Use any text edit to add below line right under <ExtraData>, and set the resolution that you want, make sure it is the same resolution was what you set in the com.apple.Boot.plist file.
      <ExtraDataItem name="CustomVideoMode1" value="1280x800x32"/>

The final xml should look something like below:

... ...
    <ExtraData>
      <ExtraDataItem name="CustomVideoMode1" value="1280x800x32"/>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
... ...

 

Good luck and your mileage may vary.