squi has asked for the wisdom of the Perl Monks concerning the following question:

right now we have a link like <a href="http://www.domain.com/script.cgi?www.new-domain.com" target="_blank">this</a>

and the perl script looks like this

print "Location: http://$link\n\n"; $link = "www.oldhouseinteriors.com";

and it mostly works, but sometimes we get this error in the new window

Document moved This document has temporarily moved here

any ideas?

Replies are listed 'Best First'.
Re: redirect to a NEW window
by amt (Monk) on Sep 30, 2004 at 18:12 UTC
    From HTTP/1.1: Status Code Definitions:

    10.3.3 302 Found

    The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.

    The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

    If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

    Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client.

    If for some reason you are posting to that script, the RFC states the client MUST NOT automatically forward the client when the method is something other than GET or HEAD.

    amt.

    perlcheat
Re: redirect to a NEW window
by tachyon (Chancellor) on Oct 01, 2004 at 02:04 UTC

    If your perl script really looked like that it should not work as you define $link after you use it.... You could try a 303 or 302 with full status line.

    my $link = "domain.com"; # 302 is the usual print "Status: 302 Found\nLocation: http://$link/\n\n"; # 303 may be more reliable print "Status: 303 See Other\n:Location: http://$link/\n\n";

    cheers

    tachyon

      tachyon, I'm not sure what all this URI and 302/303 is all about, but adding Status: 302... works wonders. I presume I add one or the other, not both. Thank you, --Sandra

        Yes, you add one or the other. Every HTTP response includes a Status code. Usual ones are 200 OK, 404 Not Found, 500 Internal Server Error. The 3xx status codes are redirects.

        cheers

        tachyon

Re: redirect to a NEW window
by Grygonos (Chaplain) on Sep 30, 2004 at 17:05 UTC

      no, _blank is correct for opening in a new window.

      target="some_window_name" means "open the link in the windows called 'some_window_name'. If there is no such window, open one.

      target="_new" means "open the link in the windows called '_new'. If there is no such window, open one.

      target="_blank" means "open the link in a new windows".