mod_rewrite and Concrete5
I was trying to additionally rewrite an URL before letting the classical Concrete5 mod_rewrite happen – everything matched to index.php, like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Íf you try to paste any additional RewriteRule before this catch-all rule, your Apache will run into an endless loop, probably giving up with a 500 error. Your log will show something like:
access.log
(…) “GET” “114.ideaday.de” “/stellenmarkt/stellenangebote/” “redirect:/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/stellenmarkt/stellenangebote/”
error.log[Sun Jan 24 16:57:52 2010] [error] [client 85.181.108.54] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.
Apparently mod_rewrite fails to recognize index.php as already being rewritten and keeps looping through the rule over and over again. Recent versions of Apache will stop after 10 iterations and yield a 500 error.
After nearly giving up, I’ve figured out a solution how to do this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /RewriteRule ^stellenmarkt/stellengesuche/(.*)-([0-9]+)[/]*$ stellenmarkt/stellengesuche/gdemo/?id=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
As you see, the additional rule is placed before the Rewrite Conditions! This works, no more endless loops :-)