You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Chris Brooks <ma...@gmail.com> on 2010/01/26 18:32:31 UTC

[users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

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
daemon.

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/
detail.pl?url_name=$1&model_nbr=$2

On the first server this successfully matches this request:

http://www.mydomain.com/products/whirlpool/1234567.html, and does an
internal redirect to /perl/detail.pl?url_name=whirlpool&model_nbr=1234567

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:

192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(2) init rewrite engine with requested uri /products/whirlpool/1234567.html
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(3) applying pattern '/products/(.*)/(.*)\.html$' to uri
'/products/whirlpool/1234567.html'
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(2) *rewrite /products/whirlpool/1234567.**html -> /perl/
detail.pl?url_name=&model_nbr=*
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(3) *split uri=/perl/detail.pl?url_name=&model_nbr= -> uri=/perl/detail.pl,
args=url_name=&model_nbr=*
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(2) local path result: /perl/detail.pl
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(2) prefixed with document_root to /www/perl/mydomain/htdocs/perl/detail.pl
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial<http://www.mydomain.com/sid#9094fec][rid%2390a8b3c/initial>]
(1) go-ahead with /www/perl/mydomain/htdocs/perl/detail.pl [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/
detail.pl?url_name=$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?

Thanks,
Chris

Re: [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

Posted by Chris Brooks <ma...@gmail.com>.
Hi Eric,

Yes, both are 1.3.

I don't have Apache2.pm -- the mod_perl2 module -- installed.

[root@data2 ~]# perl -MApache2 -le 'print mod_perl->VERSION'
Can't locate Apache2.pm in @INC (@INC contains: /www/perl/
/usr/local/lib/perl5/5.8.7/i686-linux /usr/local/lib/perl5/5.8.7
/usr/local/lib/perl5/site_perl/5.8.7/i686-linux
/usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl .).

Thank you for taking the time to help!
Chris

On Wed, Jan 27, 2010 at 8:43 AM, Eric Covener <co...@gmail.com> wrote:

> On Wed, Jan 27, 2010 at 8:38 AM, Chris Brooks <ma...@gmail.com> wrote:
> > Hi Eric,
> >
> > Thanks for the note.  Both apache and mod_perl are up-to-date:
> >
> > [root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
> > Server version: Apache/1.3.41 (Unix)
> > Server built:   Sep  2 2009 15:34:13
>
> Both systems are 1.3?
>
> --
> Eric Covener
> covener@gmail.com
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

Posted by Eric Covener <co...@gmail.com>.
On Wed, Jan 27, 2010 at 8:38 AM, Chris Brooks <ma...@gmail.com> wrote:
> Hi Eric,
>
> Thanks for the note.  Both apache and mod_perl are up-to-date:
>
> [root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
> Server version: Apache/1.3.41 (Unix)
> Server built:   Sep  2 2009 15:34:13

Both systems are 1.3?

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

Posted by Chris Brooks <ma...@gmail.com>.
Hi Eric,

Thanks for the note.  Both apache and mod_perl are up-to-date:

[root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
Server version: Apache/1.3.41 (Unix)
Server built:   Sep  2 2009 15:34:13

[root@data2 ~]# perl -Mmod_perl -le 'print mod_perl->VERSION'
1.31

Thanks,
Chris

On Wed, Jan 27, 2010 at 7:53 AM, Eric Covener <co...@gmail.com> wrote:

> On Tue, Jan 26, 2010 at 12:32 PM, Chris Brooks <ma...@gmail.com> wrote:
> > 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
> > daemon.
> >
>
> What are the versions involved?
>
> --
> Eric Covener
> covener@gmail.com
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

Posted by Eric Covener <co...@gmail.com>.
On Tue, Jan 26, 2010 at 12:32 PM, Chris Brooks <ma...@gmail.com> wrote:
> 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
> daemon.
>

What are the versions involved?

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

Posted by Chris Brooks <ma...@gmail.com>.
Good morning Krist,

Thank you very much for your reply.

No, I don't have any <perl> blocks in the httpd.conf, although this is a
mod_perl enabled apache daemon.

Thanks,
Chris

On Wed, Jan 27, 2010 at 5:16 AM, Krist van Besien <krist.vanbesien@gmail.com
> wrote:

> On Tue, Jan 26, 2010 at 6:32 PM, Chris Brooks <ma...@gmail.com> wrote:
>
>
> > Any suggestions as to what might be going on?
>
> You are not using any <perl> sections by chance, are you?
>
> Krist
>
> --
> krist.vanbesien@gmail.com
> krist@vanbesien.org
> Bremgarten b. Bern, Switzerland
> --
> A: It reverses the normal flow of conversation.
> Q: What's wrong with top-posting?
> A: Top-posting.
> Q: What's the biggest scourge on plain text email discussions?
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] mod_rewrite problem: $1 and $2 not substituted into target url

Posted by Krist van Besien <kr...@gmail.com>.
On Tue, Jan 26, 2010 at 6:32 PM, Chris Brooks <ma...@gmail.com> wrote:


> Any suggestions as to what might be going on?

You are not using any <perl> sections by chance, are you?

Krist

-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org