php - Apache Regexp 500 Internal Error ← (PHP, CodeIgniter)

I want to rewrite all incoming URLs like: host/lang-EN/product to host/index.php?lang=lang-EN/product I want to do this for all URLs not changing anything what's after the host/lang-EN/ just forward it to host/index.php?lang=lang-EN/whatever was after lang-EN/

This is what I've tried:

RewriteEngine On

RewriteRule     ^(.*)$               index.php/$1   [NC,L]
RewriteRule     ^index.php/(.*)/?$   index.php?lang=$1  [NC,L]

Resulting in Internal Error threw by Apache(last version). I am using Codeigniter as framework.

error.log:

[Sat Apr 05 12:59:32.044771 2014] [core:error] [pid 3600:tid 1680] [client ::1:3253] `AH00124: 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.`

Answer



Solution:

Try with only this one to redirect /host/... to /host/index.php...

RewriteRule     ^/?(?!index\.php)(.*)$         index.php?lang=$1   [NC,L]

(?!index.php) is negative lookahead to check that there is no index.php at the beginning. So that it doesn't touch the urls like /index.php?lang=... to avoid recursively.

Source