php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38141 $_SERVER['SCRIPT_NAME'] set incorrectly with mod_rewrite
Submitted: 2006-07-19 11:49 UTC Modified: 2008-11-26 07:56 UTC
Votes:8
Avg. Score:4.5 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:5 (71.4%)
From: martel at post dot pl Assigned:
Status: Not a bug Package: Apache2 related
PHP Version: 5.1.4 OS: Linux Gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: martel at post dot pl
New email:
PHP Version: OS:

 

 [2006-07-19 11:49 UTC] martel at post dot pl
Description:
------------
$_SERVER['SCRIPT_NAME'] is set incorrectly depending on where you place the mod_rewrite rule. If it is placed in .htaccess, the SCRIPT_NAME is initialized correctly but when you place the same rule in VirtualHost in server config it is an empty string.

Not sure if it is a PHP or Apache bug but I'll start here.

The rule is:

    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1

Or (it's not relevant - both have the same result):

    RewriteEngine On
    RewriteRule !\.(js|ico|gif|jpg|png|css|swf)$ index.php

Apache2 SAPI. Apache version is 2.0.58 but I guess it may not be relevant. 


Reproduce code:
---------------
// For the URL of 'http://test.nebula.intranet/archive/2006/06'. 
// File 'index.php' is located at the root of virtual host (http://test.nebula.intranet/index.php).

var_dump($_SERVER['SCRIPT_NAME']);

Expected result:
----------------
string(10) "/index.php"

Actual result:
--------------
string(0) ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-19 12:19 UTC] martel at post dot pl
Tested it some more. 

When the RewriteRule is placed under <Directory> or .htaccess it is set correctly. When placed under <VirtualHost> it is initialized with some bogus value.
 [2006-07-23 12:49 UTC] sniper@php.net
It's some Apache bug/feature since we only set SCRIPT_NAME to whatever Apache returns.
 [2006-08-03 12:33 UTC] martel at post dot pl
I have created an issue in the apache bugtracker. After short discussion and a lot of examples they claim it's not an Apache bug but the mod_php one.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40102
 [2006-08-03 13:18 UTC] martel at post dot pl
Nick Kew mentioned what the problem may be. These following points are the result of his best guess (it's a direct copy of his words):

(1) SCRIPT_NAME is set by ap_add_cgi_vars in Apache's "util_script".
(2) PHP presumably calls that somewhere - unless it's reinvented that wheel.
(3) The bug *looks like* a case of PHP calling it too early - specifically *before* the rewrite happened - so of course there was no SCRIPT_NAME.
(4) So a fix would be for mod_php to call it later.  Or maybe even call it twice, if the early call is unavoidable.
 [2006-08-05 19:38 UTC] tony2001@php.net
I updated the report in Apache bug system.
 [2008-11-26 01:16 UTC] lbarnaud@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.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Reproduced with a shell script executed as CGI, not a PHP bug (updated Apache bug).
 [2008-11-26 07:56 UTC] martel at post dot pl
Thank you all for taking your time to analyze this bug and furthermore for active monitoring of it's status. Your work is greatly appreciated. 

Now, I unfortunately have to destroy this sweet mood. This bug shows what the problem with open sourced and free software is. This bug is more than two years old and what? After two years we finally know it's related to Apache and not to PHP. Woohoo! I wonder how much time it will take to actually fix the issue ;)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC