Ajax software
Free javascripts
↑
Main Page
The moral of the story? Keep a tidy shop. Return 404s for all deleted pages. Some search engine marketers
suggest redirecting old products to semantically related products instead of 404ing. This preserves link
equity, whereas a 404 does not. This can be done in
.htaccess
or PHP with a 301 redirect, and is demon-
strated later in this chapter.
Avoiding Indexing Error Pages Using 500
Once upon a time, in a place far away, your web server is chugging along; everything is fine and dandy.
Then, all of a sudden, something terrible happens, and the database goes down. Because this is an unan-
ticipated error condition (all of us could do better error checking!), many pages return erroneous blank
pages or perhaps 404s. Perhaps the web server goes down altogether. Worse still, you don’t have a hot
standby to replace it. Meanwhile, search engines are trying to index your pages, not finding anything,
getting blank pages, and so on. Here are the possibilities:
?
Returning 404s or blank pages.
This is a real problem. If a server returns a 404, a search engine
will de-list your pages. If a search engine sees blank pages, or pages full of errors, it may do the
same. This should be avoided at all costs.
?
Not finding anything (no connection).
This is actually more desirable than it sounds in terms
of indexing. Although it may look extremely unprofessional, a search engine is likely to assume
that there are intermittent connectivity problems and try again later. Your users may, however,
be annoyed. At least from a spider ’s point of view, though, as long as this is resolved in a day
or so, there is no major problem.
It’s actually fairly simple. A “500” status code can be returned, along with a custom page describing the
error. This indicates to search engines that there is a temporary technical problem. Perhaps the site is
down for maintenance. Say it politely and provide the time it will be back up. Or perhaps there was a
national disaster as in the case of certain web servers in the New Orleans area in 2006. Put up a global
error page for every URL with a polite message, and wait for things to clear up.
To do this in PHP use this line of PHP, and then add whatever content you wish:
header(‘HTTP/1.0 500 Internal Server Error’);
echo ‘The bank is closed until the scary aliens leave on their space ship; sorry
for the inconvenience, thank you for being a Bank of Mars customer.’;
exit();
Redirecting with PHP and mod_rewrite
From now on, this chapter primarily discusses uses of the 301 HTTP status code. You can implement it
with either mod_rewrite or PHP.
When using mod_rewrite, redirecting is implemented similarly to URL rewriting, except that you spec-
ify a redirection status code as a parameter. The following rule does a 301 redirect to
bar.php
when the
initial request is for
foo.php
:
RewriteRule ^foo\.php$ /bar.php [R=301,L]
84
Chapter 4: Content Relocation and HTTP Status Codes
c04.qxd:c04 10:40 84
Ajax software
Free javascripts
→