CGI Redirect to another page

Andrew Clover and-google at doxdesk.com
Thu Sep 25 17:24:58 EDT 2003


John J. Lee <jjl at pobox.com> wrote:

> I know I don't like them "on principle", but what practical problems
> do they cause?  Do proper HTTP redirects avoid the "back button trap",
> maybe?

Yes, they do. They are also more widely supported by robots (including
search engine spiders) and older and non-desktop browsers (as well as
newer browsers which can have meta-refresh and/or JavaScript disabled).

An HTTP redirect is an unequivocal statement that a resource is elsewhere,
at a transport level. It can be understood and acted on by agents with no
knowledge of HTML or JavaScript (for example Python's urllib), and can
potentially be used to automatically update links.

Meta-refresh (or, less commonly used, Refresh as an HTTP header) was
designed for re-fetching pages that update themselves, such as webcams.
It's still useful for this, although it has yet to be standardised.

Using meta-refresh or JavaScript for a redirect is really a misuse,
and is needed only:

  a. When you need to set a cookie at the same time as doing a redirect.
     Some browsers will not allow a cookie to be set in anything but a
     '200 OK' response.

  b. When your web hosts are exceedingly crappy and don't allow you to
     do proper redirects through server config or CGI.

In these cases I prefer to use JavaScript's location.replace() method (which
also avoids the back button trap), combined with a short-delay meta-refresh
as backup and a plain HTML link in the returned page as backup for the
backup (for robots etc).

Alan Kennedy <alanmk at hotmail.com> wrote:

> It is claimed that search engines treat meta-refresh with suspicion.
> I don't know if this is true or not.

It's not easy to tell, but Google is known to have 'anti-cloaking' measures
for detecting search engine abuse. Since meta-refresh is commonly used for
sending browsers to a different page than engines, it is possible that
a meta-refresh - likely combined with other indicators Google could find
suspicious - might result in a PR0 block.

More importantly, many robots won't follow a meta-refresh at all. (After all,
they don't want to end up following an infinitely refreshing webcam page.)
So a backup <a> link should always be included.

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/




More information about the Python-list mailing list