【问题标题】:mod rewrite recursion errormod重写递归错误
【发布时间】:2017-01-14 11:27:01
【问题描述】:

我有一个 .htaccess 文件,它使用下面的指令将请求重定向到 php API。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule api/v1/(.*)$ api/v1/index.php?request=$1 [QSA,NC,L]
</IfModule>

RewriteRule 似乎导致了重定向递归错误。我在同一托管公司的另一台 Apache 服务器上运行完全相同的指令和 API,在生产中完全没有问题。两个站点都从一个子域运行,每个站点都在一个单独的共享主机帐户上。

两个共享主机上的文件夹结构相同:

├── root
│   ├── subdom
│   │   ├── .htaccess
│   │   ├── api
│   │   │    ├── v1
│   │   │    │   ├── index.php (API entry point) 

这是错误日志中捕获的错误,API中的index.php没有捕获到错误。

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.

我比较了 phpinfo 的输出,所有的设置和版本都是一样的。

测试:

此方法在其中一个共享主机帐户上失败

subdom.domain.com/api/v1/endpoint/arg

此方法适用于两个共享主机帐户

domain.com/subdom/api/v1/endpoint/arg

此方法在两个托管帐户上都没有错误地命中 api

subdom.domain.com/api/v1/

【问题讨论】:

  • 在这两种情况下检查%{REQUEST_FILENAME}的内容。

标签: apache .htaccess mod-rewrite


【解决方案1】:

尝试添加:

RewriteBase / 

或者改变(/):

RewriteRule api/v1/(.*)$ /api/v1/index.php?request=$1 [QSA,NC,L]

【讨论】:

  • 它现在可以正常工作了。我最终在这里添加了一个正斜杠:/api/v1/index.php?request=$1 [QSA,NC,L]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-04
相关资源
最近更新 更多