Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 04-29-2007, 06:51 AM   #1
LQ Newbie
Registered: May 2005
Posts: 4

Rep: Reputation: 0
Apache mod_rewrite RewriteCond infinite loop problem


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!


Last edited by jika; 04-29-2007 at 09:56 AM.
Old 04-29-2007, 09:01 AM   #2
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
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:
RewriteEngine On
ReWriteCond %{REQUEST_URI} !^/$
ReWriteCond %{REQUEST_URI} !^$
RewriteCond %{REQUEST_URI} !^/balancer$
RewriteRule ^/(.*)$ / [R,L]
Old 05-01-2007, 08:25 AM   #3
LQ Newbie
Registered: May 2005
Posts: 4

Original Poster
Rep: Reputation: 0
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:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/balancer$
RewriteRule ^/(.*)$ /index.html [L]
All requests except those targeting /balancer are redirected to /index.html.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Infinite Loop ewt3y Programming 3 08-16-2005 10:48 AM
Java Stopping an Infinite loop oulevon Programming 3 10-18-2004 11:11 PM
infinite loop beginner_84 Programming 5 08-15-2004 03:32 AM
facing problem in increment operator of set :infinite LOOP ashwinipahuja Programming 0 06-03-2004 01:05 AM
Sendmail build - infinite loop?? kstarks Linux - Software 0 10-02-2003 08:13 AM

All times are GMT -5. The time now is 09:27 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration