You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Greg Allen <ga...@mycalet.com> on 2011/04/02 22:18:55 UTC

[users@httpd] Problems with mod_rewrite

Hello,

I am having problems getting mod_rewrite to work for me.  I have a 
simple rewrite program
written in perl.  I have configured rewrite in the httpd.conf file and 
turned on logging. It looks
as though my map program is being called, but no value is being returned 
from the program (as
you can see from the rewrite.log.

I've included all the relevant files - httpd.conf, rewrite.pl, and 
rewrite.log.

Can anyone tell me what is wrong?

Thanks,

-- Greg

httpd.conf:

RewriteEngine on
RewriteLog /tmp/rewrite.log
RewriteLogLevel 9
RewriteMap mymap prg:/tmp/rewrite.pl
RewriteRule /foo/? ${mymap:$1}

/tmp/rewrite.pl:

#!/usr/bin/perl -i

# Disable buffered I/O which would lead to deadloops for the Apache server.

$| = 1;

while (<STDIN>) {
     s|^foo/|bar/|;
     print $_;
}

/tmp/rewrite.log:

127.0.0.1 - - [02/Apr/2011:15:06:42 --0400] 
[localhost/sid#9d50a38][rid#9faa2b8/initial] (2) init rewrite engine 
with requested uri /foo/
127.0.0.1 - - [02/Apr/2011:15:06:42 --0400] 
[localhost/sid#9d50a38][rid#9faa2b8/initial] (3) applying pattern 
'/foo/?' to uri '/foo/'
127.0.0.1 - - [02/Apr/2011:15:06:42 --0400] 
[localhost/sid#9d50a38][rid#9faa2b8/initial] (5) map lookup OK: 
map=mymap key= -> val=
127.0.0.1 - - [02/Apr/2011:15:06:42 --0400] 
[localhost/sid#9d50a38][rid#9faa2b8/initial] (2) rewrite '/foo/' -> ''
127.0.0.1 - - [02/Apr/2011:15:06:42 --0400] 
[localhost/sid#9d50a38][rid#9faa2b8/initial] (2) local path result:


---------------------------------------------------------------------
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] Problems with mod_rewrite

Posted by Greg Allen <ga...@mycalet.com>.
Thanks!  That was it.  I knew it was something simple....

-- Greg

On 4/2/2011 5:01 PM, Eric Covener wrote:
> You have to capture something to use $1 as your key
> On Apr 2, 2011 4:19 PM, "Greg Allen"<ga...@mycalet.com>  wrote:
>> Hello,
>>
>> I am having problems getting mod_rewrite to work for me. I have a
>> simple rewrite program
>> written in perl. I have configured rewrite in the httpd.conf file and
>> turned on logging. It looks
>> as though my map program is being called, but no value is being returned
>> from the program (as
>> you can see from the rewrite.log.
>>
>> I've included all the relevant files - httpd.conf, rewrite.pl, and
>> rewrite.log.
>>
>> Can anyone tell me what is wrong?
>>
>> Thanks,
>>
>> -- Greg
>>
>> httpd.conf:
>>
>> RewriteEngine on
>> RewriteLog /tmp/rewrite.log
>> RewriteLogLevel 9
>> RewriteMap mymap prg:/tmp/rewrite.pl
>> RewriteRule /foo/? ${mymap:$1}
>>
>> /tmp/rewrite.pl:
>>
>> #!/usr/bin/perl -i
>>
>> # Disable buffered I/O which would lead to deadloops for the Apache
> server.
>> $| = 1;
>>
>> while (<STDIN>) {
>> s|^foo/|bar/|;
>> print $_;
>> }
>>
>> /tmp/rewrite.log:
>>
>> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
>> [localhost/sid#9d50a38][rid#9faa2b8/initial] (2) init rewrite engine
>> with requested uri /foo/
>> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
>> [localhost/sid#9d50a38][rid#9faa2b8/initial] (3) applying pattern
>> '/foo/?' to uri '/foo/'
>> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
>> [localhost/sid#9d50a38][rid#9faa2b8/initial] (5) map lookup OK:
>> map=mymap key= ->  val=
>> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
>> [localhost/sid#9d50a38][rid#9faa2b8/initial] (2) rewrite '/foo/' ->  ''
>> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
>> [localhost/sid#9d50a38][rid#9faa2b8/initial] (2) local path result:
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>

-- 
Greg Allen
Calet, LLC
gallen@mycalet.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] Problems with mod_rewrite

Posted by Eric Covener <co...@gmail.com>.
You have to capture something to use $1 as your key
On Apr 2, 2011 4:19 PM, "Greg Allen" <ga...@mycalet.com> wrote:
> Hello,
>
> I am having problems getting mod_rewrite to work for me. I have a
> simple rewrite program
> written in perl. I have configured rewrite in the httpd.conf file and
> turned on logging. It looks
> as though my map program is being called, but no value is being returned
> from the program (as
> you can see from the rewrite.log.
>
> I've included all the relevant files - httpd.conf, rewrite.pl, and
> rewrite.log.
>
> Can anyone tell me what is wrong?
>
> Thanks,
>
> -- Greg
>
> httpd.conf:
>
> RewriteEngine on
> RewriteLog /tmp/rewrite.log
> RewriteLogLevel 9
> RewriteMap mymap prg:/tmp/rewrite.pl
> RewriteRule /foo/? ${mymap:$1}
>
> /tmp/rewrite.pl:
>
> #!/usr/bin/perl -i
>
> # Disable buffered I/O which would lead to deadloops for the Apache
server.
>
> $| = 1;
>
> while (<STDIN>) {
> s|^foo/|bar/|;
> print $_;
> }
>
> /tmp/rewrite.log:
>
> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
> [localhost/sid#9d50a38][rid#9faa2b8/initial] (2) init rewrite engine
> with requested uri /foo/
> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
> [localhost/sid#9d50a38][rid#9faa2b8/initial] (3) applying pattern
> '/foo/?' to uri '/foo/'
> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
> [localhost/sid#9d50a38][rid#9faa2b8/initial] (5) map lookup OK:
> map=mymap key= -> val=
> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
> [localhost/sid#9d50a38][rid#9faa2b8/initial] (2) rewrite '/foo/' -> ''
> 127.0.0.1 - - [02/Apr/2011:15:06:42 --0400]
> [localhost/sid#9d50a38][rid#9faa2b8/initial] (2) local path result:
>
>
> ---------------------------------------------------------------------
> 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
>