Grant McLean wrote:
I've seen a number of code examples for redirects which output a root-relative URI in the Location header. Eg:
Location: /images/item1.gif
Although browsers seem to accept this and do 'the right thing', the HTTP RFC seems to be pretty clear that the Location header must be an absolute URI. Am I reading it wrong?
no.
Is there an easy way to get the absolute URI of the current request to use with Apache::URI->parse to translate a relative URI to absolute?
I have managed to get the hostname, port number and path components
individually from the request object and paste them together but it's all a bit messy.
to generate a URI that points to the same server as the current request it's best to use Apache::URI methods, which are pretty easy.
my $uri = Apache::URI->parse($r); $uri->path('/some/new/document.html'); my $absolute_uri = $uri->unparse;
note that calling path() (or any other method) is optional - you don't need to change anything in order to unparse() the URI and get an absolute URI back.
Apache::URI::parse() can take an optional second argument, which it will then parse and use as the base for the URI (in place of the current request).
HTH
--Geoff