You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by ricardo13 <ri...@gmail.com> on 2009/05/27 16:12:48 UTC

[users@httpd] Rewrite doesn't work !!

Hi,

I have a web cluster and use mod_rewrite to forward request to cluster,
according with type of request.
There is a external program in directive RewriteMap to classify requests.

My external program:
...
 while(1) {
      fscanf(stdin, "%s", input); // read input ---> format = /1, or /2, /3
...
      sscanf(strchr(input,'/') + 1, "%d", &number);  // extract only number
of format

      switch(number) {
	case 1: fputs("192.168.1.11", stdout); break;
	case 2: fputs("192.168.1.22"); break;
     	default: fprintf(stdout, "/bad_url"); break;
      }

      fputc('\n', stdout);
      fflush(stdout);
------------------------------------------------
My http.conf:

        RewriteEngine on
	RewriteLog /usr/local/apache2/logs/rewrite_log
  	RewriteLogLevel 5
	RewriteLock /usr/local/apache2/logs/file.lock
 	RewriteMap prgmap prg:/usr/local/apache2/admControl

	RewriteCond ${prgmap:$1} !=/bad_url
	RewriteRule ^/(.*) http://${prgmap:$1}/ [P]
	
	RewriteRule ^(.*) - [F]

My problem is, don't proxy request to cluster. See log file:

(2) init rewrite engine with requested uri /1
(3) applying pattern '^/(.*)' to uri '/1'
(5) map lookup OK: map=prgmap key=1 -> val=
(4) RewriteCond: input='' pattern='!=/bad_url' => matched
(5) map lookup OK: map=prgmap key=1 -> val=
(2) rewrite '/1' -> 'http:///'
(2) forcing proxy-throughput with http:///
(1) go-ahead with proxy request proxy:http:/// [OK]

What's happen ??? Why mod_rewrite doesn't proxy requests to ip address ???

Thank you
Ricardo 
-- 
View this message in context: http://www.nabble.com/Rewrite-doesn%27t-work-%21%21-tp23743331p23743331.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.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] Rewrite doesn't work !!

Posted by ricardo figueiredo <ri...@gmail.com>.
Great Eric,

You're right !!!  The problem was the slash in RewriteRule (RewriteRule
^/(.*) http://${prgmap:$1}/ [P] ).

Now, I have one more doubt.

My external program forward request with URL with final /1, or /2 and others
URL  (for example, /3, /4, /5, etc...) I would like drop.
The external program drops request rewriting URL to "/bad_url".

My httpd.conf has these directive and It means for me:

RewriteCond ${prgmap:$1} =/bad_url           # if (prgmap == "/bad_url")
RewriteRule (.*) - [F]                                  #         drop
request
RewriteRule ^(.*) http://${prgmap:$1}/ [P]     # else forward to machine
with IP address

But, When external program rewrite to "/bad_url" then happen it.

(2) init rewrite engine with requested uri /1
(3) applying pattern '${prgmap:$1}' to uri '/1'
(3) applying pattern '^(.*)' to uri '/1'
(5) map lookup OK: map=prgmap key=/1 -> val=/bad_url
(2) rewrite '/1' -> 'http:///bad_url/'
(2) forcing proxy-throughput with http:///bad_url/
(1) go-ahead with proxy request proxy:http:///bad_url/ [OK]

How I drop request instead forward to cluster ???

Thank you
Ricardo





On Wed, May 27, 2009 at 4:29 PM, ricardo figueiredo <
ricardoogrande@gmail.com> wrote:

> Hi,
>
> I run the program outside of Apache, and it works perfeclty (How I would
> like). When typed 'http://localhost/1' in browser, the variable number is
> assigned value 1.
>
> Why mod_rewrite doesn't rewrite URL ??? I'm writing IP address to output
> program.
>
> Thank You
> Ricardo
>
>
>
> On Wed, May 27, 2009 at 3:04 PM, Eric Covener <co...@gmail.com> wrote:
>
>> >      sscanf(strchr(input,'/') + 1, "%d", &number);  // extract only
>> number
>>
>> >        RewriteRule ^/(.*) http://${prgmap:$1}/ [P]
>>
>> > (5) map lookup OK: map=prgmap key=1 -> val=
>>
>> Decide whether your passing in something with a slash or not.  Does
>> your program do the right thing when run outside of Apache?
>>
>>
>> --
>> 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
>>
>>
>
>
> --
> Muito Obrigado
>
> Ricardo
>



-- 
Muito Obrigado

Ricardo

Re: [users@httpd] Rewrite doesn't work !!

Posted by ricardo figueiredo <ri...@gmail.com>.
Hi,

I run the program outside of Apache, and it works perfeclty (How I would
like). When typed 'http://localhost/1' in browser, the variable number is
assigned value 1.

Why mod_rewrite doesn't rewrite URL ??? I'm writing IP address to output
program.

Thank You
Ricardo


On Wed, May 27, 2009 at 3:04 PM, Eric Covener <co...@gmail.com> wrote:

> >      sscanf(strchr(input,'/') + 1, "%d", &number);  // extract only
> number
>
> >        RewriteRule ^/(.*) http://${prgmap:$1}/ [P]
>
> > (5) map lookup OK: map=prgmap key=1 -> val=
>
> Decide whether your passing in something with a slash or not.  Does
> your program do the right thing when run outside of Apache?
>
>
> --
> 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
>
>


-- 
Muito Obrigado

Ricardo

Re: [users@httpd] Rewrite doesn't work !!

Posted by Eric Covener <co...@gmail.com>.
>      sscanf(strchr(input,'/') + 1, "%d", &number);  // extract only number

>        RewriteRule ^/(.*) http://${prgmap:$1}/ [P]

> (5) map lookup OK: map=prgmap key=1 -> val=

Decide whether your passing in something with a slash or not.  Does
your program do the right thing when run outside of Apache?


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