The Wayback Machine - https://web.archive.org/web/20081201151548/http://www.webreference.com/html/tutorial30/3.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 30 / 3

index1234567

HTTP for HTML Authors, Part III

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Down with the 404

Even after you've done all of this, however, you will often be confronted with a situation when a URL has to change, and the old URL will point to nothing. One way to avoid leaving your users with the ugly 404 response is to create a page that kindly informs the users that this page has moved and redirects them to the new page.

Although this is a useful technique, it has a few disadvantages. First of all, users have to make another HTTP request to get the page, and the first one is wasted displaying the useless message. Secondly, search engines visiting your site will keep indexing the old page, and also be confused about which page is the right page when counting the number of links to your site.

HTTP offers a function that can achieve the eradication of 404s much more easily. It is called redirecting and works by setting one of the HTTP status codes starting with 3 in the response to an HTTP request.

Say I request the old version of the press release URL from Acme's server, but the admins have gotten their act together and cleaned up the URLs. The HTTP response would look something like this:

HTTP/1.1 301 Moved Permanently
Location: http://www.acme.com/news/morons13release

This tells the user agent that this resource has been moved to the URL specified by the Location header and that we won't be seeing anything like it at this URL again (notice the “Permanently” bit). Most browsers will immediately load the new URL and display the page; some of the smarter ones will even update any bookmarks the user has to the new URL, while search engines will stop caring about the old URL and update their records.

301 Moved Permanently is by far the most useful redirect code, but a few others you might find useful are 302 Found, 303 See Other and 307 Temporary Redirect. They work in exactly the same way as 301 Moved Permanently, but with some slight differences in semantics.

302 Found basically means that the initial URL was some sort of query that returned a specific result, which resides in the new URL. In this way, it tells the user agent that the new URL is not a wholesale replacement for the old one, just that the resource the user agent was looking for can be found at the new URL for now, but this may change later.

303 See Other is used to redirect to a different URL because the current URL doesn't have anything to display. A good example of when this is appropriate is a Web-based e-mail service. Say the user writes a message in an HTML form and then submits the form in order to send the message. The URL of the form submission will cause the message to be sent, but the user must now be sent back to his Inbox. In this case the server could send a 303 See Other response after processing the message in order to point the user in the right direction.

307 Temporary Redirect works very similarly to 302 Found, but implies more of a temporary solution. For instance, if a Web server is overloaded it might use 307 Temporary Redirect to point the user agent to a “mirror” (a copy on a different server) of the requester resource. This implies to user agents that even though they should get the resource from the new URL now, they should come back to the original URL if they need it at a later time.

Configuring your Web server software to send these codes in appropriate situations is something that varies a lot form server to server, so consult your server's documentation to find out how to use these response codes in your site.

index1234567

Next Page...

http://www.internet.com/

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

URL: http://www.webreference.com/html/tutorial30/3.html

Produced by Stephanos Piperoglou
Created: March 15, 2001
Revised: March 16, 2001

Morty Proxy This is a proxified and sanitized view of the page, visit original site.