HTTP redirection : Java Glossary


HTTP redirection
How Redirection Works Importance to a Webmaster Looking After External Links
Importance to a Browser User Benefits of Maintaining Clean Links
Importance to a Programmer Links
Importance to a Webmaster Looking After Internal Links

How Redirection Works

When you are browsing, you may have noticed a that sometimes the browser serves you a URL (Uniform Resource Locator) different from the one you requested. Here is what happened. You asked for a certain URL, but the server noticed it listed in its tables as redirected or renamed. The server sends back the name of the replacement URL and a 301 response code, meaning the URL has changed/moved permanently. In theory, the browser is supposed to make a note of the new URL for future reference. The browser then makes a new request for the revised URL.

Sometimes this process can take several iterations before you finally get at the page you wanted. It is a bit of an idiotic way to do things. The server should just send you want you want on the first try. I think the idea is they want to punish you with needless delay for not making note of the new URL for future reference.

Sometimes, the server redirects you to a totally different website. Sometimes it gives a 302 response code, meaning the redirection is only temporary and you should continue to use the original URL in future. There are other response codes in the 300 to 399 range for other rarer types of redirection.

Redirection Importance to a Browser User

When you notice a redirection, you can update your bookmarks so you go directly in future. The trouble is, the browser will not tell you if a redirect is permanent or temporary. A temporary redirect will likely not work at all in future. Generally temporary URLs (Uniform Resource Locators) are long and full of gibberish.

Redirection Importance to a Programmer

In Java, your computer programs can simulate a browser and go exploring the Internet. If you use the com.mindprod.http.HTTP package, it will let you configure to either hide the redirects (and just show you the final result), or show you each leg explicitly.

Redirection Importance to a Webmaster Looking After Internal Links

If you are maintaining a website, you discontinue, rename, reorganize and move pages around. To be kind to you visitors, you want to arrange things so when they use the old names, they are taken to the new documents.

There are two ways to do this.

  1. The faster and cleaner way is to configure some tables in your HTTP (Hypertext Transfer Protocol) server listing the various redirects. If you used the Apache HTTP static server, the configuration file looks like this in a simple case:

    You must specify the new URL in full even if it is within the same site. # starts a comment. This information goes in configuration files: either .htaccess for per directory control, or httpd.conf, at the root of the Apache installation.

  2. A klutzier way but that does not require access to the server configuration is to create dummy marker file in the old spot that looks like this:
    <!-- macro Moved bgloss/bgloss.html -->

    This technique only works for *.html files. You cannot use it to redirect *.xml PAD (Portable Application Description) files, for example.

Redirection Importance to a Webmaster Looking After External Links

Ideally links on your site should be aware of any redirects. You should update your links. However, browsers don’t tell you about them. Other sites don’t inform you about them. It is up to you to test your links each day and replace links with the corresponding redirections. Very few websites bother to do this. The result is their links gradually get more and more out of date. Eventually they stop working altogether. Other than hiring a third world village to test your links each day, what can you do?

I wrote a free program called BrokenLinks to handle this. In addition to monitoring redirects, it monitors broken links. If they stay broken for 5 days or so (configurable), it warns me about them. I then have to fix the problem manually.

Benefits of Maintaining Clean Links

By daily staying on top of redirections and broken links, visitors to my site discover that:

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number