php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19265 header + relative location + cgi + aliasmatch fails
Submitted: 2002-09-06 09:36 UTC Modified: 2002-10-08 12:38 UTC
Votes:2
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: steve at bluearena dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4CVS-2002-09-06 OS: Linux
Private report: No CVE-ID: None
 [2002-09-06 09:36 UTC] steve at bluearena dot com
I have run into a problem with the above setup on both the latest snapshot and also 4.2.2 - sorry if it's not a bug.

<?
if(!$test) die(header("Location: /?test=true"));
else die("redirected ok: $REQUEST_URI");
?>

This works fine, and as expected, the output is:
redirected ok: /?test=true

However if I have the following lines in my httpd.conf:
DocumentRoot /home/bla/html
AliasMatch ^/sess/(.{4})/(.*) /home/bla/html/$2

And change the script to:
<?
if(!$test) die(header("Location: /sess/1234/?test=true"));
else die("redirected ok: $REQUEST_URI");
?>

The output is:
redirected ok: /

I'm not quite sure what is going on here. I have just switched from an Apache module to CGI version for security reasons and wasn't quite expecting this problem so came into an interesting problem, a loop in my program, and crashes out with an error 500:

GET / HTTP/1.0
host: www.mydomain.com

HTTP/1.1 500 Internal Server Error
Date: Fri, 06 Sep 2002 14:30:35 GMT
Server: Apache/1.3.26 (Unix) PHP/4.2.2 mod_ssl/2.8.10 OpenSSL/0.9.6g
X-Powered-By: PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3, PHP/4.2.3
Connection: close
Content-Type: text/html; charset=iso-8859-1


Changing it to a absolute URL in the header("Location   fixes the problem but it would be a pain to change this in all my scripts. Thanks a lot for your help.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-06 19:40 UTC] yohgaki@php.net
First of all, your redirect is wrong.
You must use absolute URI for Location header.

Try absolute URI, if it fixes.

 [2002-09-07 06:28 UTC] steve at bluearena dot com
A relative location works most of the time. It always works with the Apache module, and the CGI version only fails when the aliasmatch directive is set.

Anyway, I worked around this by using mod_rewrite instead of AliasMatch, so I'm not particularly bothered - but I'm quite sure that a lot of people use relative URIs with the Location header so it might be worth looking into.

I realise the official standard says the URIs should be absolute, but IE, Netscape, and Lynx, maybe others, support relative.

Steve
 [2002-10-08 12:09 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

If people use incorrect (relative pathes) in the Location: header they cannot expect consistent behaviour. It may work in some browser and it may not work in others. 
 [2002-10-08 12:38 UTC] steve at bluearena dot com
I am trying to demonstrate that the same PHP code which works on the Apache module, fails with the CGI module. Both with Internet Explorer as the client.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC