php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24520 Rewriting an URL with mod_rewrite does not register variables properly.
Submitted: 2003-07-07 05:27 UTC Modified: 2003-07-08 03:36 UTC
From: kouber@php.net Assigned:
Status: Not a bug Package: Apache related
PHP Version: 4.3.3RC2-dev OS: Win2000 NT
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: kouber@php.net
New email:
PHP Version: OS:

 

 [2003-07-07 05:27 UTC] kouber@php.net
Description:
------------
When I write some RewriteRule with additional "redirected" variables, they seem to be empty in my script.

RewriteRule ([a-z]+/)?([0-9]+) job_view.php?job_sid=$2&theme=$1

When I call the following URL "http://localhost/gray/56", I expect in my script to have these variables:

job_sid => string(2) "56"
theme => string(4) "gray"

But what var_dump($job_sid) and var_dump($theme) actually tells me is:

job_sid => string(2) "56"
theme => string(0) ""

Note that $theme is an empty string, but not null.

The weirdest thing is that var_dump($_GET) shows correct result:

array(2) {
  ["job_sid"]=>
  string(2) "56"
  ["theme"]=>
  string(4) "gray"
}

I forgot to mention, that I have register_globals=On, so I expect ALL of my $_GET variables to be registered as globals.

Reproduce code:
---------------
var_dump($_GET);
var_dump($job_sid);
var_dump($theme);

Expected result:
----------------
array(2) {
  ["job_sid"]=>
  string(2) "56"
  ["theme"]=>
  string(4) "gray"
}
string(2) "56"
string(4) "gray"

Actual result:
--------------
array(2) {
  ["job_sid"]=>
  string(2) "56"
  ["theme"]=>
  string(4) "gray"
}
string(2) "56"
string(0) ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-07 05:35 UTC] kouber@php.net
The actual RewriteRule is:

RewriteRule ([a-z]+)?/?([0-9]+) job_view.php?job_sid=$2&theme=$1

which excludes the slash (/) from the $theme variable. As described, theme should be string(5) "gray/".
 [2003-07-07 10:04 UTC] kouber@php.net
Same behaviour.
 [2003-07-07 11:01 UTC] sniper@php.net
Works fine here with these settings:

<VirtualHost *>
    ServerName localhost
    
    RewriteEngine on
    RewriteRule ([a-z]+)?/?([0-9]+) /rewrite.php?job_sid=$2&theme=$1
    
    DocumentRoot /www/apache/htdocs/
    php_value register_globals 1
</VirtualHost>

You propably just have something wrong with your settings.

 [2003-07-08 03:36 UTC] kouber@php.net
Nobody's fault, but mine.

Sorry.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 10:01:38 2025 UTC