Fun With 404
24th June 2007
More Options Than 404
You know what happens when your browser asks a server for
a page that isn’t there. The server sends a status code to
the browser telling it “404 Not Found” — and your browser
gives you a message related to that.
Some browsers simply repeat what the server sent, with
maybe a line or two about which page wasn’t found. The
IE browser, if “friendly” error messages are specified in
preferences, might give you a page of whys and wherefores
and options and links and such which, if you’re so inclined,
you can wade through and come to the conclusion that the
page the browser tried to get doesn’t exist.
But the message doesn’t have to be “404 Not Found”. Several
other common messages are addressed in this article.
But first, let’s clarify how the browser and server talk to
each other — behind the scenes, so to speak. Stuff goes on
that you don’t see.
How Browser and Server Talk To Each Other
The browser asks for a web page file (or an image file or
a flash file or whatever). It’s a straight-forward “I want
this” with the URL of the file the browser wants. Sometimes
information in addition to the URL is sent to the server,
like the data of a form submission.
When the server responds, it first sends information just
for the browser. This header is one or more lines of plain
text.
When the server sends a blank line, the browser knows the
header information is done and anything that follows is to
be displayed in the browser window.
The information in the header varies. Some of the
information that can be in the header are cookies, an
indication of how much content follows the header, the
date the file was last updated, whether or not it is okay
to queue the page, and encrypted passwords.
Included in the header information is a status code.
More Than Just 404 Can Be Used
When the browser asks for a web page and the server is able
to find it and send it to the browser, a “200 Okay” status
code is sent in the header.
Search engine robots appear to servers as if they were
browsers. And search engine robots pay attention to the
status codes that servers send in the header.
When the server can’t find the requested page, the status
code is “404 Not Found” — usually. Several of the other
status codes the server might send to the browser when a
page isn’t available are
- 301 Moved Permanently
- 307 Temporary Redirect
- 410 Gone
Each of those are addressed below.
301 Moved Permanently
This indicates the file at the URL was moved, permanently,
and the server can send the new URL to the browser.
Some browsers might display a “301 Moved Permanently” to
the user. Other browsers automatically redirect the user
to the new URL.
Search engine robots can make a note of the URL for
immediate or later indexing. They will probably remove
the old URL from the index.
When a file at a URL is moved, from
http://example.com/contact/index.shtml to
http://example.com/contact.html for example, this status
code can be sent to browsers and robots to let the software
know the status of the page, including its new location.
When people repeatedly ask for a non-existent URL, like
when another web site misspells the file name in a link, for
example, this status code can be used. Browser users and
robots can be sent to where they really wanted to go.
307 Temporary Redirect
The file at the URL has moved, temporarily, and the server
can send the temporary alternate URL to the browser.
Some browsers might display a “307 Temporary Redirect” to
the user, with or without additional information. Other
browsers automatically redirect the user to the temporary
alternate URL.
Search engine robots can make a note of the alternate URL.
They might or might not do an immediate or later indexing
of it.
When a URL is temporarily unavailable, browsers and robots
can be redirected to an alternate URL. For example, a URL
to a script that’s down for maintenance or modification can
be redirected to a page explaining the situation.
Suppose a webmaster has published a special page with a
sale or urgent news. The page will remain on the web site
only a few days. Lots of traffic to that page is desired.
In such or similar situations, several or many other URLs
of the web site can be set up to temporarily redirect all
their traffic to the special page.
410 Gone
The file at the URL is no longer available and the server
knows it is permanently gone.
This tells browsers and robots that the file at the URL is
intentionally unavailable and that remote links to the file
should be removed.
This status can be used for files that had been available
for a limited time, such as the special web page mentioned
in the previous section.
(If the server doesn’t know or can’t determine whether or
not the file is permanently gone, “404 Not Found” should
be used instead.)
Telling the Server What To Say
Two methods exist to tell the server what to say to
browsers, with the .htaccess file and with software.
Using .htaccess To Tell the Server What To Say
In the .htaccess file, type this line:
Redirect ___A___ ___B___ ___C___
Replace the A, B, and C underscore sections with:
___A___
This is replaced with the status code number the server
shall send to the browser.
___B___
This is the URL-path of the missing file, the part of
the URL that’s left after the http:// and domain name
are removed. For example, the URL-path of
http://example.com/rover/index.html is /rover/index.html
___C___
This is the complete http://… new or alternate URL.
(Status code 410 would not have a URL here.)
Here are examples:
Redirect 301 /rover/index.html http://example.com/books.html Redirect 307 /rover/index.html http://example.com/books.html Redirect 410 /rover/index.html
The first example tells browsers and robots that
/rover/index.html has been permanently moved to new URL
http://example.com/books.html
The second example states that it’s a temporary redirect.
The third example says /rover/index.html is permanently
gone.
Entire directories can be redirected at once. Thus,
Redirect 301 /rover http://example.com/other
tells browsers and robots that every file in the “/rover”
directory is moved permanently to http://example.com/other
with corresponding file names.
Use a plain text word processor like NotePad or BBEdit when
typing the “Redirect…” lines into the .htaccess file. And
have the FTP program up/download the file as plain text
instead of binary.
Using Software To Tell the Server What To Say
Master 404-Terminator™ can be used to do things the
easy way.
This software lists all unhandled 404 URLs that browsers
and robots have attempted. You then specify how to handle
the request should it happen again.
Any of the 301, 307, 410 status codes can be specified. In
addition, a “403 Forbidden” status code is available to be
sent to browsers and robots — which in this case pretends
the file at the requested URL actually does exist but that
a password or other permission is required for access.
Master 404-Terminator™ accepts wild cards. This means
you can redirect entire directories or file name patterns
with the status code of your choice.
The manual contains instructions., but here is an example.
If you decide to use SSI on your web site and change all
your web page file names from .html to .shtml, these
form fields (everything is done in a control panel)
will catch all 404 URLs with .html file names and redirect
the browser/robot with status “301 Moved Permanently” to
the corresponding URL with file name extension .shtml
Easy. Quick. Painless setup.
Master 404-Terminator™ also has the option of replacing
a file instead of redirecting to a new file. This comes in
very handy for image, JavaScript, CSS, and other files that
pages require for proper display.
Use the same method as the redirect, except use the
“replace” radio button instead.
It can eliminate broken images and such on web pages.
Click here to read about Master 404-Terminator™
Will Bontrager, Programmer
© 2005, 2006 Bontrager Connection LLC
(Article syndication powered by Master Syndication Gateway V2)
Posted in Money, Online Business, Marketing and Promotion, Writing and Publishing, Computers and Internet | Comments Off

















