【发布时间】:2014-04-05 11:19:46
【问题描述】:
我想重写所有传入的 URL,例如:host/lang-EN/product 到 host/index.php?lang=lang-EN/product 我想对所有 URL 执行此操作,而不改变任何 host/lang-EN/ 之后的内容,只需将其转发到 host/index.php?lang=lang-EN/whatever was after lang-EN/
这是我尝试过的:
RewriteEngine On
RewriteRule ^(.*)$ index.php/$1 [NC,L]
RewriteRule ^index.php/(.*)/?$ index.php?lang=$1 [NC,L]
导致 Apache 抛出内部错误(最新版本)。我正在使用 Codeigniter 作为框架。
错误日志:
[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.`
【问题讨论】:
-
error.log文件中是否有条目?
-
是的,我现在也加入了。
-
当然这会创建一个无休止的重定向,因为在“下一轮”(在 .htaccess 中配置的重写会循环多次,直到不再匹配任何规则)
^(.*)$当然匹配又是你的index.php?lang=foo。 -
@CBroe 目标是获取一个类似
host/lang-EN/product的url,然后用它调用>host/index.php?lang=lang-EN/product。 -
@CBroe 第一个规则应该匹配
/lang-EN并重定向到index.php/lang-EN然后第二个重写应该再次执行,这将匹配index.php/lang-EN并执行index.php?lang=lang-EN
标签: php regex apache codeigniter