【问题标题】:Apache Regexp 500 Internal ErrorApache 正则表达式 500 内部错误
【发布时间】:2014-04-05 11:19:46
【问题描述】:

我想重写所有传入的 URL,例如:host/lang-EN/producthost/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


【解决方案1】:

尝试仅使用这个将/host/... 重定向到/host/index.php...

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

(?!index.php) 是负前瞻,以检查开头是否没有index.php。这样它就不会触及像/index.php?lang=... 这样的url,以避免递归。

【讨论】:

  • 引发内部错误[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. 可能是 Codeigniter 之后执行的操作触发了错误。
  • @Berky 您是否删除了其他两个条件并只使用了我的一个?
  • @SabujHassan:我认为host 是这里的实际主机名(域名),所以它不应该是 RewriteRule 模式的一部分。
  • @SabujHassan 我删除了我的规则并用你的规则替换了它,所以我只有一个条件。
  • @CBroe 我也排除了这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-21
  • 1970-01-01
  • 1970-01-01
  • 2011-11-01
相关资源
最近更新 更多