views:

20

answers:

2

Hi,

This is the htaccess I have: Options +FollowSymlinks

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pages
RewriteRule ^(.+)/$ /$1 [NC]
RewriteRule ^$ /pages/index.php [NC]
RewriteRule ^([a-z]+)\?([^/]+)$ /pages/$1.php?$2 [NC]
RewriteRule ^([a-z]+)/([^/]+)$ /pages/$1.php?q=$2 [NC]
RewriteRule ^([a-z]+)$ /pages/$1.php [NC]
ErrorDocument 404 /pages/404.php

What is should do is quite simple:

  • remove trailing slash from URL
  • direct example.com/tomato to example.com/pages/tomato.php
  • direct example.com/tomato?c=red&size=big to example.com/pages/tomato.php?c=red&size=big
  • direct example.com/tomato/red to example.com/pages/tomato.php?q=r

But this is the problem: any URL of the for /pages/tomato.php matches line 7 of the .htaccess which would produce an infinite loop. That's why I added an exception for /pages but it seems to be ignored - I still get 500 Internal Server Error with this log message:

mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.

Could this have something to do with the fact that I'm running this with virual hosts? If so, what should be done to fix it?

+1  A: 

RewriteCond only applies to the next RewriteRule, so you have to copy that condition for every rule.

Fabian
Thanks, is there a way to make it apply to all the following rules without copying it again and again?
jorenl
A: 

You could use a break rule in front of your other rules:

RewriteRule ^pages/ - [L]
Gumbo
Thank you. It turned out that it this case, it was sufficient to add the RewriteCond only to one other RewriteRule, but I will certainly remember this for the future.
jorenl