Site Redirect
Join the Discussion
If you have an idea for a web site then a good way to start out is to initially create the site on free web hosting. This gives you the opportunity to start building up the site without it costing you any money.
Eventually, as your site grows and starts to become successful you will want to move it onto its own paid hosting. This will most likely mean that the domain name where your site can be found will change. Since the free hosting that you are moving from almost certainly wont provide a way to set up server side redirection to your new site you will need to place code into all of your web pages to do the redirection.
One way to handle the redirection is using the HTML meta tag.
content="0;url=http://www.mydomain.com/thispage.htm" />
Of course if it is against the terms of service of our free hosting to use an immediate redirect we can easily add a delay by changing the 0 into say 5 to add a five second delay before the redirect. The problem with coding this though is that you have to alter every single page on your site individually to reference the corresponding page on the new location. If there are dozens or hundreds of pages on your site then this will be a big task.
If you are using Javascript on your site then you may have a common function library that is already linked into all of your web pages. If this is the case then we can set up a Javascript redirect within that head script instead and have the one command used by all of our web pages without having to touch the pages themselves.
All we need to do to achieve the desired result is to find out the filename of the current page and transfer to the corresponding page on the new domain.
Getting the filename is easy, particularly if you use the Current Page Reference script that will split the page reference into its component parts for us. Then all we need to do is to activate a redirect to the new location. We can do this by adding just one additional line to the end of the page reference script.
Of course if we don't want this to run straight away we put the code into a function and call it to a settimeout call instead. So to get our five second delay we can use:
var uri = new Object();
getURL(uri);
location.href = 'http:\/\/www.mydomain.com\/' + uri.file;
}
setTimeout('redirect()',5000);
Of course you will want to specify your new domain name where I have put www.mydomain.com in the above code. You will also need to make sure that all of your pages are copied to the new location exactly as on the old site except for this redirect code.

