cakephp 由于可能的配置错误,请求超过了10个内部重定向的限制

inn6fuwd  于 2022-11-11  发布在  PHP
关注(0)|答案(6)|浏览(140)

我在我的CakePHP应用程序中遇到以下错误:
“可能由于配置错误,请求超过了10个内部重定向得限制.如有必要,请使用”LimitInternalRecursion“增加限制.使用”LogLevel debug“获取回溯跟踪.,引用站点:”http://projectname.dev/
根文件夹中的My .htaccess如下所示:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

和应用程序文件夹中:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

在webroot文件夹中:

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

我正在遵循这个教程:
http://book.cakephp.org/2.0/en/getting-started.html

yr9zkbsy

yr9zkbsy1#

我刚刚在这里找到了解决问题的办法:
https://willcodeforcoffee.com/cakephp/2007/01/31/cakephp-error-500-too-many-redirects.html
webroot中的.htaccess文件应如下所示:

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

而不是:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /projectname
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
yruzcnhs

yruzcnhs2#

//Just add 

RewriteBase /
//after 
RewriteEngine On

//and you are done....

//so it should be 

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
bxgwgixi

bxgwgixi3#

我通过www.example.com解决了这个问题http://willcodeforcoffee.com/2007/01/31/cakephp-error-500-too-many-redirects/只需取消注解或添加以下内容:

RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

到您的.htaccess文件

vlurs2pr

vlurs2pr4#

我在调试PHP header()函数时遇到了这个错误:

header('Location: /aaa/bbb/ccc'); // error

如果我使用相对路径,它的工作:

header('Location: aaa/bbb/ccc'); // success, but not what I wanted

但是,当我使用/aaa/bbb/ccc这样的绝对路径时,它会给出确切的错误:
由于可能存在配置错误,请求超过了10个内部重定向得限制.如有必要,请使用“LimitInternalRecursion”增加限制.使用“LogLevel debug”获取回溯跟踪.
看起来header函数在内部重定向,而没有进入HTTP,这很奇怪。经过一些测试和尝试,我找到了在header()后添加exit的解决方案:

header('Location: /aaa/bbb/ccc');
exit;

而且它工作正常。

n6lpvg4x

n6lpvg4x5#

按照cakePHP官方文档,.htaccess应该是这样的:
https://book.cakephp.org/2/en/installation/url-rewriting.html

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
9udxz4iz

9udxz4iz6#

简单地删除内部.htaccess文件中的重写基础就修复了我的问题。就像a在我的根目录中有一个htaccess文件,只是链接到我的根文件夹中的公共目录中的索引页,然后我有另一个htaccess文件重写每个请求到同一个公共文件夹中的索引页,并删除RewriteBase就修复了我的问题。如下所示
这是根目录中的第一个.htaccess文件

相关问题