LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache mod_rewrite CondRewrite infinite loop problem (http://www.linuxquestions.org/questions/linux-server-73/apache-mod_rewrite-condrewrite-infinite-loop-problem-549887/)

jika 04-29-2007 05:51 AM

Apache mod_rewrite RewriteCond infinite loop problem
 
Hi,

short description of situation:

I have a reverse proxy built from Apache 2.2.3 with load balancing using mod_balancer. For security reasons I need to redirect all locations different from /balancer (Load Balancer web interface) to server root (/).

I made a following piece of code which should do the job but it creates an infnite loop instead:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/balancer$
RewriteRule ^/(.*)$ / [R,L]


When I remove the exclamation from the second line, it works, but does exactly opposite of desired - rewrites only requests for /balancer, everything else is untouched. I suppose misconfiguration somewhere in negation of second line but I can't find it...

Someone any idea?

Thanks for help!

jika

zaichik 04-29-2007 08:01 AM

If the request is not /balancer then it gets rewritten to /, which is also not balancer, so it gets rewritten again to / and so on. Throw in another couple rules:
Code:

RewriteEngine On
ReWriteCond %{REQUEST_URI} !^/$
ReWriteCond %{REQUEST_URI} !^$
RewriteCond %{REQUEST_URI} !^/balancer$
RewriteRule ^/(.*)$ / [R,L]


jika 05-01-2007 07:25 AM

zaichik, thanks for help. However it is not working exactly as expected - all requests are rewritten to / - it is impossible to reach /balancer. This is caused by the first line of your code - all requests match it.
Finally I made it a little different way, which is not 100% I wanted at the beginning, but it is satisfactory enough for me:
Code:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/balancer$
RewriteRule ^/(.*)$ /index.html [L]

All requests except those targeting /balancer are redirected to /index.html.


All times are GMT -5. The time now is 01:22 PM.