Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to redirect to

So I have the rule (mod_rewrite)

<Location />
    RewriteEngine on
    RewriteRule /(.*) /bar/index.php/$1 [L]

This config caused a infinite loop, how to fix?


share|improve this question
You should use RewriteMatch first. – Ency Jan 22 '11 at 15:53
See Redmumba's answer for how to fix. This is why: "Remember, however, that if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule." (mod_rewrite docs for [L]). Your rule is saying to redirect every request to /bar/index.php/$1, then this becomes a request, so it is redirected to /bar/index.php/$1, then this becomes a request... – DerfK Jan 22 '11 at 16:24
up vote 2 down vote accepted

Like Ency suggested, you'll want to make sure that you insure you're NOT trying to access index.php:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/bar/index.php/.*
RewriteRule /(.*) /bar/index.php/$1 [L]

Hope this helps.

share|improve this answer
When I removed <Location />, seems working without adding your Line2 – Howard Jan 22 '11 at 16:22

You should try adding the RewriteCond: RewriteCond %{HTTP_USER_AGENT} ^Mozilla.Chrome.$

That should prevent the infinite loop* by executing the redirect only when the request comes from a browser.

*- Am assuming apache redirected request will either have an empty http header HTTP_USER_AGENT/apache, not the original header. P.S: you might want to add ie's http header to the list.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.