#38141 [Opn]: $_SERVER['SCRIPT_NAME'] set incorrectly with mod_rewrite
| From: | martel at post dot pl | Date: | Thu, 03 Aug 2006 13:18:38 +0000 |
| Subject: | #38141 [Opn]: $_SERVER['SCRIPT_NAME'] set incorrectly with mod_rewrite | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-100280@lists.php.net to get a copy of this message | ||
ID: 38141
User updated by: martel at post dot pl
Reported By: martel at post dot pl
Status: Open
Bug Type: Apache2 related
Operating System: Linux Gentoo
PHP Version: 5.1.4
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2006-08-03 12:33:31] 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-07-23 12:49:29] sniper@php.net
It's some Apache bug/feature since we only set SCRIPT_NAME to whatever
Apache returns.
------------------------------------------------------------------------
[2006-07-19 12:19:50] 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-19 11:49:55] 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) ""
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38141&edit=1