httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Brooks <>
Subject [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url
Date Tue, 26 Jan 2010 17:32:31 GMT
Good morning Apache list,

I have a strange mod_rewrite problem, and I'm not sure how to solve it.  I
have a RewriteRule that works correctly on one apache daemon, but doesn't
work when copied and pasted to the httpd.conf file of a second apache

To state this differently, on the second apache daemon, mod_rewrite is
correctly matching the URL based on the regex, but it is not substituting
the back-references into the target URL.

The rule looks like this:

RewriteRule /products/(.*)/(.*)\.html$ /perl/$1&model_nbr=$2

On the first server this successfully matches this request:, and does an
internal redirect to /perl/

On the 2nd (malfunctioning) server, it doesn't work -- although mod_rewrite
correctly matches the request to the rule, it doesn't substitute the values
inside the parentheses to $1 and $2 in the output URL.  Here's what gets
written to the output of the RewriteLog on the 2nd server: - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(2) init rewrite engine with requested uri /products/whirlpool/1234567.html - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(3) applying pattern '/products/(.*)/(.*)\.html$' to uri
'/products/whirlpool/1234567.html' - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(2) *rewrite /products/whirlpool/1234567.**html -> /perl/* - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(3) *split uri=/perl/ -> uri=/perl/,
args=url_name=&model_nbr=* - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(2) local path result: /perl/ - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(2) prefixed with document_root to /www/perl/mydomain/htdocs/perl/ - - [26/Jan/2010:10:17:06 -0600] [][rid#90a8b3c/initial<][rid%2390a8b3c/initial>]
(1) go-ahead with /www/perl/mydomain/htdocs/perl/ [OK]

Note the bolded sections of the log -- the values stored in $1 and $2 are
not substituted into the final URL.  On the first server, these do get
substituted AND they get written to the rewrite_log.

Here's the relevant section of the httpd.conf file for the malfunctioning
Apache daemon:

RewriteEngine On

RewriteLog /var/log/apache-perl/rewrite_log.log
RewriteLogLevel 3

RewriteRule /products/(.*)/(.*)\.html$ /perl/$1&model_nbr=$2

I thought it was possible that there were conflicts with other rules, so I
removed all the other RewriteRules and made sure that there were no
.htaccess files that applied to this request.  I also tried hard-coding the
url_name param to "whirlpool", on the theory that mod_rewrite might be happy
with 1 substitution param, but no dice.  In this case it still declined to
substitute "1234567" for $1.  This httpd.conf file has no other virtual
hosts which might be causing a conflict.

Any suggestions as to what might be going on?


View raw message