Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to redirect www.example.com/foo to www.example.com/bar/index.php/foo

So I have the rule (mod_rewrite)

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

This config caused a infinite loop, how to fix?

Thanks.

share|improve this question
    
You should use RewriteMatch first. –  Ency Jan 22 '11 at 15:53
1  
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

2 Answers 2

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

 
discard

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.