473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Location header question

I have been using the HTTP "Location" reponse header to direct
a symbolic request to a CGI program to an actual URL/file. For
example, let us suppose the CGI program's table indicates
xyz -> /this/that/the.other.thing.html, then redirect.cgi?xyz
results in the page /this/that... being sent. redirect.cgi
is usually in another directory than the page it is to supply.
This works fine as far as it goes.

A problem arises when the actual URL contains, for example,
image sources in its own directory. The file names are not
sought relative to the current URL (apparently) -- the one
supplied by the "Location:" header -- but (perhaps?) to the
previous URL. So the images can't be found and either a
blank or an error icon results, depending on the browser.
The browser in this case is either a recent Mozilla or
Firefox browser. I have not tried this with IE which under
interdiction in the client's office anyway.

The HTTP 1.1 specification says,

14.30 Location

The Location response-header field is used to redirect the
recipient to a location other than the Request-URI for
completion of the request or identification of a new resource.
For 201 (Created) responses, the Location is that of the
new resource which was created by the request. For 3xx
responses, the location SHOULD indicate the server's preferred
URI for automatic redirection to the resource. The field
value consists of a single absolute URI.

Location = "Location" ":" absoluteURI

An example is:

Location: http://www.w3.org/pub/WWW/People.html

My usage (in the CGI program) has been to send the Location
response, e.g. "Location: /this/that/the.other.thing.html" in
response to "redirector.cgi?xyz" coming from an HREF. I
notice the example has the full site name. I would prefer
to avoid this since the names of the sites involved might
change from time to time, necessitating the change of
configuration files and the checking thereof. For the time
being I can assume the location target will be on the same
site as the CGI.

It seems to me that the specification implies that, once
the browser has begun reading the page, it should use its
virtual path (/this/that/) as a prefix for any relative
src or href targets in the file. But maybe I'm doing something
wrong, or misunderstanding the specification. Your comments
or ideas would be appreciated.

Clearly, there are schemes by which this problem can be
solved, such as reading the target page and rewriting the
href and src targets, but I would prefer not to go to all
that error-inviting trouble and just feed the location if
I can (and get the browser to read the relative links
correctly).

Dec 9 '05 #1
6 2869
"G*rd*n" wrote:
The HTTP 1.1 specification says,

14.30 Location

... The field value consists of a single absolute URI.

Location = "Location" ":" absoluteURI


My usage (in the CGI program) has been to send the Location
response, e.g. "Location: /this/that/the.other.thing.html" in
response to "redirector.cgi?xyz" coming from an HREF. I
notice the example has the full site name. I would prefer
to avoid this since the names of the sites involved might
change from time to time


So you realize that a partial URL is invalid content for a Location header,
but you still think you should carry on this way? This is just laziness on
your part.

I'm not aware of a single server scripting language that doesn't allow you
to find out the host name of the domain where the script is being executed.
(In PHP, fpr example, you can use $_SERVER["HTTP_HOST"]).

You've made a good start by reading the HTTP specification. Now try reading
the documentation of your server scripting language.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Dec 9 '05 #2
> "G*rd*n" wrote:
The HTTP 1.1 specification says,

14.30 Location

... The field value consists of a single absolute URI.

Location = "Location" ":" absoluteURI
My usage (in the CGI program) has been to send the Location
response, e.g. "Location: /this/that/the.other.thing.html" in
response to "redirector.cgi?xyz" coming from an HREF. I
notice the example has the full site name. I would prefer
to avoid this since the names of the sites involved might
change from time to time


Philip Ronan <in*****@invalid.invalid>: So you realize that a partial URL is invalid content for a Location header,
but you still think you should carry on this way? This is just laziness on
your part.

Laziness is supposed to be a virtue in programmers. I have
managed some enthusiastic programmers in the past and they
can get you in a _lot_ of trouble, although not in as much
trouble as enthusiastic lawyers.

However, laziness notwithstanding, I do need stuff to work.
Scripting is not a problem; the problem is my too-lazy guess
about what I could get away with in using the Location header.
I suppose the relative addresses I supplied should not have
worked at all. In any case, I will concoct absolute URIs as
defined in the HTTP specs and see if that works.

Thanks for your help.

I'm not aware of a single server scripting language that doesn't allow you
to find out the host name of the domain where the script is being executed.
(In PHP, fpr example, you can use $_SERVER["HTTP_HOST"]).

You've made a good start by reading the HTTP specification. Now try reading
the documentation of your server scripting language.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Dec 9 '05 #3
Philip Ronan wrote:
My usage (in the CGI program) has been to send the Location
response, e.g. "Location: /this/that/the.other.thing.html" in
response to "redirector.cgi?xyz" coming from an HREF. I
notice the example has the full site name. I would prefer
to avoid this since the names of the sites involved might
change from time to time

So you realize that a partial URL is invalid content for a Location header,


HTTP Location header, yes.

CGI Location header is different: there's no requirement to send the
full URL.

Confusing? Exactly:-)

--
Nick Kew
Dec 9 '05 #4
Nick Kew wrote:
CGI Location header is different: there's no requirement to send the
full URL.


Why? Does the CGI spec mandate munging of the header to an absolute URL? Do
the common CGI libraries do the munging for you?

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Dec 9 '05 #5
> >>My usage (in the CGI program) has been to send the Location
response, e.g. "Location: /this/that/the.other.thing.html" in
response to "redirector.cgi?xyz" coming from an HREF. I
notice the example has the full site name. I would prefer
to avoid this since the names of the sites involved might
change from time to time

Philip Ronan wrote: So you realize that a partial URL is invalid content for a Location header,

Nick Kew <ni**@asgard.webthing.com>: HTTP Location header, yes.

CGI Location header is different: there's no requirement to send the
full URL.

Confusing? Exactly:-)


According to http://cgi-spec.golux.com/issues-120-detailed.html:

# The "Location" header field and relative URIs

The Location response header field description doesn't conform to current practice as relative URLs
seem to be acceptable for redirects. (hmmm... I wonder if this is an HTTP/1.1 issue also). This
description limits the Location to use with GET/HEAD which is in conflict with HTTP/1.1.

[a reply:] Here's a grey area. The specification in this draft does not match that in the NCSA
documentation, which provides for limited local redirects internal to the server (they don't get
sent back to the client as a 'real' redirect). So that's a break with current practice that needs to
be fixed. On the other hand, the grey area starts forming because this is overloading an HTTP header
field (Location, which takes only an absoluteURI) with a CGI field that has different semantics
(Location, which can take an absoluteURI or a server-local URI [with some restrictions]). I'm not
sure how to handle this; perhaps define the CGI semantics but make a note that this is also the name
of an HTTP field with differing ones? Suggestions? I've discussed the overloading issue briefly with
Roy Fielding, and he remarked that it should be safe to avoid this sort of collision by naming CGI
header fields with a "CGI-" prefix.

Status:
Open

According to a great number of other pages purporting to tell
how to use the Location header from CGI, it's the same as the
HTTP Location header. W3C's page on CGI points to the above.

Dec 10 '05 #6
On Fri, 9 Dec 2005, G*rd*n wrote:
Philip Ronan <in*****@invalid.invalid>:
So you realize that a partial URL is invalid content for a
Location header, but you still think you should carry on this way?
This is just laziness on your part.
Laziness is supposed to be a virtue in programmers.


The Perl community has a rather good understanding of "laziness"
in this sense. It doesn't mean what many superficial commentators
suppose it to mean. I haven't worked out where you stand on that
question, so "no offence intended".
I have managed some enthusiastic programmers in the past and they
can get you in a _lot_ of trouble, although not in as much trouble
as enthusiastic lawyers.
The truly lazy programmer will save themself from unnecessary and
complicated debugging work by following the published specifications
whenever possible, instead of trying to "get away with it".

The original CGI spec has two defined variants of the *CGI* Location:
header:

1. an absolute external URL (leads to a 30x HTTP response and
a properly-specified *HTTP* Location: header)

2. an absolute URL path (i.e without any initial "http://"
part). This is required to be resolved internally by the
server, and will not result in any 30x response nor HTTP
Location: header.

Best place I know for current specification status is the
informational RFC http://www.ietf.org/rfc/rfc3875 , see section 6.3.2.

All else is a potential grey area - even if the spec were to be
clarified by trying to specify the behaviour of some subset of
that grey area, it wouldn't be binding on existing applications, so
the lazy programmer would do well to avoid pointless extra work by
confining themselves to the existing defined cases.
However, laziness notwithstanding, I do need stuff to work.


But first define "work", for cases where the interworking
specification does not say what's to happen. The usual sloppy answer
"does what I intended, with the software that I tried" would be
disqualified by any truly-lazy programmer.

IMHO, anyway
Dec 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg...
4
by: Jeff | last post by:
I've been able to find this question on a Google group search but not the answer. Plus I'm a late convert to php transferring over from ASP. I hope this isn't too many strikes against me. When I...
10
by: Margaret MacDonald | last post by:
I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about. I have some code that does some processing and then does a...
0
by: chotiwallah | last post by:
there has been a thread about this topic a couple of days ago, but nothing was really solved there ...
13
by: Will Pittenger | last post by:
I have a Control derived class. When the parent of the control changes the control's Location property, the stack overflows. I have not found a way to find out what was on the stack when it does...
23
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target...
2
by: Ladbroke | last post by:
Hiya, got a little prob with the syntax for header ( ' Location .... with variable). Usually examples are given with a complete URL, like: ..... header( 'Location: login/testsite/start.php'...
6
by: P-Rage | last post by:
Hello everyone, I was wondering what could possibly cause Internet Explorer 6 to loop a page usging a header(Location:) statement. For example, a page called 'page1.php': if((isset($_POST))...
5
by: One | last post by:
Hi guys - I have a problem after a client clicks a Confirm button on a form - the form processes the data, inserts into a database, and then redirects using header Location. I have tested this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.