Redirect and form data
JQ Johnson
jqj at darkwing.uoregon.edu
Sun Dec 13 10:24:47 EST 1998
Several replies have addressed parts of the question by leif.andersson
about redirecting, but seem to have missed the key point: how to do a
redirect if the original URL is a POST with form data associated with it?
The answer, so far as I know, is that it is impossible -- when a browser
receives a redirect, it always tries the new URL using a GET method.
Basically, the redirection mechanism in HTTP is flawed (well, perhaps
"limited" is more appropriate) in that it returns a URL, but the
information a browser actually needs to perform an http request is a
{method,URL,data} triplet.
The only approach I know of that actually works transparently in this case
is to have a script at the old URL that acts as a proxy server --
performing the POST (or PUT or whatever) request for the user and passing
any response data back to the user. This is, of course, a rather more
tricky problem than just generating a Location: header or an HTML document
with a meta tag, and in general can't even be done with a CGI script (e.g.
for a page that is authenticated).
A partial approach that also works is to have a redirecting URL script that
generates a reply page containing a form with a bunch of hidden form
elements. Thus, if the old URL was http://x.y/old.cgi and the new one
http://a.b/new.cgi, replace old.cgi with a script that generates
<form action="http://a.b/new.cgi" method=POST>
This site has moved to http://a.b/new.cgi. Repost form data?
<input type=hidden name="n1" value="v1">
...
<input type=submit value="Yes">
</form>
old.cgi would of course generate the page dynamically using the names and
values passed to it. One can, at the risk of added complexity, then add
some javascript to the generated page that performs an automatic SUBMIT
after a timeout, etc.
JQ Johnson office: 115F Knight Library
Academic Education Coordinator phone: 1-541-346-1746 v, -3485 fax
1299 University of Oregon mailto:jqj at darkwing.uoregon.edu
Eugene, OR 97403-1299 http://darkwing.uoregon.edu/~jqj/
More information about the Web4lib
mailing list