jorenl
jorenl

Reputation: 94

.htaccess seems to be ignoring RewriteCond

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:

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?

Upvotes: 2

Views: 685

Answers (2)

Gumbo
Gumbo

Reputation: 655745

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

RewriteRule ^pages/ - [L]

Upvotes: 0

Fabian
Fabian

Reputation: 13691

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

Upvotes: 4

Related Questions