I looked around and found this code to redirect on a 'how to' website:
print "Location: $URL ";
It would not work for me at all. Got 'Internal Server error..."
I looked at another web site and found:
print "Location: $URL\n\n";
I added the \n\n and it worked!
I looked at the print function documentation at perl.com and there was nothing about the \n.
Perhaps it's about Perl in the context of CGI documentation that I need to find?
Any pointers as to what I don't understand.
Thanks
Tom
Both types (requests, responses) of message consist of a start-line, zero
or more header fields (also known as "headers"), an empty line (i.e.,
a line with nothing preceding the CRLF) indicating the end of the
header fields, and possibly a message-body.
generic-message = start-line
*(message-header CRLF)
CRLF
[ message-body ]
start-line = Request-Line Ķ Status-Line
HTTP/1.1 - 4.1 Message Types [ietf.org]
See for an explanation of quoting operators and escape sequences [perldoc.com].
Itīs not in the documentation for print [perldoc.com] since it would be wrong there. All print does is output a string or list of strings to the specified filehandle or to STDOUT. You would need to look up the docs for strings to find out about escape sequences supported in strings. But since this depends on the quoting operator used, it is documented there [perldoc.com].
print "Content-type: text/html\n\n";
The redirect is just a different header type but t still needs the 2 line breaks (\n).
Thanks, but I could not figure out what a start-line is, nor was it used in the how-tos. At least not that I noticed.
Another quick and last (hopefully) question.
The not so good how-to site had the exit() function as the last executable in the redirect script.
Is this necessary to close the script and/or clean-up the 'environment'.
Tom
I could not figure out what a start-line is
Itīs all in the little quote from the HTTP spec.
Disregard the underscore in the following text, itīs just used for alignment.
generic-message = start-line
__________________*(message-header CRLF)
__________________CRLF
__________________[ message-body ]start-line _____= Request-Line Ķ Status-Line
Perhaps it is clearer now that the alignment is ok.
A generic message in http (such as the request by the browser and the reply by the server) consists of a start-line, zero or more header fields (also known as "headers"), an empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields, and possibly a message-body.
Start-line is defined as either Request-Line or Status-Line.
A Request-Line is something like
GET / HTTP/1.1or
HEAD / HTTP/1.1
A Status-Line is the first line of a response header and looks like
HTTP/1.1 200 OKor
HTTP/1.1 400 Bad Request
As for the question about the exit have a look at the following quote:
The new permanent 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).
From that follows that your script should output some code like
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>301 Moved Permanently</TITLE>
</HEAD><BODY>
<H1>Moved Permanently</H1>
The document has moved <A HREF="http://server/">here</A>.<P>
<HR>
<ADDRESS>Apache/1.3.26 Server at server Port 80</ADDRESS>
</BODY></HTML>