Management: Redirecting Traffic

Introduction
You may find this explanation a little pedantic at times, but we want to make certain that the concepts are clear and easy to understand.

Domain name servers, which act as the alphabetical index for Internet hosts and servers, point to IP (Internet Protocol) addresses using either A (address) records or via CNAME records, which alias one host name to another resolving eventually to an Ip address through an A record.

DNS does not define port numbers or file paths. Sometimes one might want to do this (perhaps a web address / domain actually points to a file within another domain / web address). To make this work, redirection of the original URL (universal resource locator) address is used.

How Redirections Work
There are several methods available for redirecting HTTP traffic from one address to another. Here are two different methods that are used.

  • Redirections — The basic method used for many web sites is to return an HTTP302 repsonse (redirect) with the new location. This is quick and easy to do as you are essentially creating a basic html page with the redirect information in it. Unfortunately this is not as professional as the relocated URL is displayed in the address bar of the browser.
  • Cloaked pages — It is possible, to some extent, to cloak the redirection by placing it within an html frameset. This is a little more complex as you now have to create an html page with a frameset. This isn't really a redirection, but it does hide the URL change from the browers.
  • Name Based Virtual Hosting — Name based virtual hosting is a feature of the Apache server that can be used to redirect URLs. While this is a tidy way to do things, it unfortunately requires a special configuration in the http daemon's configuration files. However, it has the added advantage of improved performance and the URL redirection is completely hidden from the browser.

Redirecting To A Hosted Website
The simplest redirection is to a hosted web site service. For example, you may have a web site at this address:

http://www.myisp.com/users/~johndoe/index.htm which we can all agree is far too long and very unprofessional looking.

So you might want to redirect this, which you can do most simply by registering your domain at mydomain.com and, on your own web server, or through a redirection service, create a single html page that contains the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="refresh" content="0;url=http://www.myisp.com/users/~johndoe/index.htm">
</head>
<body>
</body>
</html>

In reality, the 'index.htm' is not required as most web servers recognize index.htm as the page to automatically load.

Redirecting Around A Port 80 Block
Most web traffic, or web servers, run on port 80. This means that if you are running a web server at home traffic sent to you home on port 80 is normally blocked by your ISP. This is done for security and bandwidth / policy restriction reasons. This does make it more difficult to run a web server at home, but not impossible.

To make this work using the code example above, the only change needed would be to the content line which would now look like this:

<meta http-equiv="REFRESH" content="0;url=http://www.myhome.com:port#/users/~johndoe/index.htm">

where port# is the number of the port you would like to use. Typically this would be something like 8080. You will note that I also changed the domain name to myhome.com (just to indicate that we are using a domain that points to your home).

There are many services that will provide automatic redirection for you.

There is one final issue you have to deal with when running a server at home and that is the issue of dynamic domain name service.

Most ISPs do not provide static, permanently assigned, IP addresses to their subscribers. This means that the IP address changes regularly, typically on a weekly basis, which would require that you update your DNS entry each time or no-one will be able to find your web site. Fortunately, there are services and utilities that take care of this dynamic DNS automatically.

One last comment... if you are running your web server at home, make sure you install a firewall between your server / home and the Internet.