Request exceeded the limit of 10 internal redirects due to probable configuration error

I'm getting the following error in my CakePHP application: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the lim...

I’m getting the following error in my CakePHP application:

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., referer: http://projectname.dev/

My .htaccess in the root folder, looks like this:

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

and in the app folder:

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

and in the webroot folder:

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

I was following this tutorial:

http://book.cakephp.org/2.0/en/getting-started.html

crmpicco's user avatar

crmpicco

16.2k25 gold badges126 silver badges208 bronze badges

asked Apr 6, 2013 at 12:17

Stephen's user avatar

I just found a solution to the problem here:

https://willcodeforcoffee.com/cakephp/2007/01/31/cakephp-error-500-too-many-redirects.html

The .htaccess file in webroot should look like:

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

instead of this:

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

Abraham's user avatar

Abraham

7,6084 gold badges44 silver badges52 bronze badges

answered Apr 6, 2013 at 12:26

Stephen's user avatar

StephenStephen

4,6558 gold badges51 silver badges78 bronze badges

7

//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]

answered Mar 22, 2018 at 14:11

Shal's user avatar

ShalShal

5735 silver badges8 bronze badges

i solved this by
http://willcodeforcoffee.com/2007/01/31/cakephp-error-500-too-many-redirects/
just uncomment or add this:

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

to your .htaccess file

answered Aug 22, 2019 at 10:28

belem's user avatar

belembelem

1711 silver badge3 bronze badges

2

This error occurred to me when I was debugging the PHP header() function:

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

If I use a relative path it works:

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

However when I use an absolute path like /aaa/bbb/ccc, it gives the exact error:

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.

It appears the header function redirects internally without going HTTP at all which is weird. After some tests and trials, I found the solution of adding exit after header():

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

And it works properly.

answered May 13, 2016 at 4:05

datasn.io's user avatar

datasn.iodatasn.io

12.4k28 gold badges111 silver badges149 bronze badges

Following the cakePHP official documentation, the .htaccess should be like this:

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>

answered Jul 11, 2021 at 8:58

R0bertinski's user avatar

R0bertinskiR0bertinski

4694 silver badges12 bronze badges

simply removing the rewrite base in the internal .htaccess file fixed mine .
like a had an htaccess file in my root directory simply linking to an index page in the public directory which is in my root folder then i had another htaccess file rewriting each request to the index page in that same public folder , and removing the RewriteBase fixe mine . as shown below

this is the first .htaccess file in the root
directory

answered Oct 5, 2021 at 2:01

oduwa's user avatar

oduwaoduwa

12 bronze badges

1

In our codeigniter with apache environment, we need to add .htaccess at to root level of application. Below is the .htaccess content;

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

answered Jan 23 at 3:56

Barbaros's user avatar

WordPress Multisite: How to fix error «Request exceeded the limit of 10 internal redirects»

I am running a WordPress multisite network with sub-directory setup. When I check my error.log file, it is full of entries like this one:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'Limit InternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

The problem was, in my case, one specific rewrite rule in the .htaccess file.

Problem description

If you open the network admin backend an go to the network admin page, then WordPress will suggest you some directives that you should put in your .htaccess file. In my case, these directives look like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]

Imagine someone requesting a URL like http://example.com/wp-content/file.txt.

If file.txt exists on the server, then Apache will deliver the file to the client because of these directives:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

If, however, file.txt does not exist as a static file on the server, these rules will not fire. But the following rewrite rule will attempt to rewrite the request URI:

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]

But in our example, the requested URL http://example.com/wp-content/file.txt will just be rewritten to itself. Then, Apache tries to process this request again, going through the rules in the .htaccess file again and again. This results in the internal redirect loop.

Solution

What we had to do was to make sure that the aforementioned rewrite rule does not fire anymore for request URIs that begin with /wp-content/. One way to achieve this is to remove the question mark from this directive. So the new rewrite rule would look like this:

RewriteRule ^([_0-9a-zA-Z-]+/)(wp-(content|admin|includes).*) $2 [L]

Another possibility would be to add an additional rewrite condition before this rewrite rule. This would look like this:

RewriteCond %{REQUEST_URI} !^/wp-(content|admin|includes).*$
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]

If you go for this solution, then you might have to adapt the rewrite condition if your RewriteBase is something else than /.

new .htaccess file

I went for the first solution. Here’s my new .htaccess file.

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)(.*.php)$ $2 [L]
RewriteRule . index.php [L]

I haven’t had any of these errors since I applied these changes.

Bug report

This bug has been reported to the WordPress developers quite some time ago. I hope there will be a fix soon.

I have a .htaccess file with the following code

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

But when I visit my site I get this error

[client 127.0.0.1] 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.

The LogLevel debug doesn’t give me a backtrace and I don’t think increasing the Limit on internal recursion is wise.

Does anyone have experience with this type of error?

asked Apr 14, 2013 at 13:59

alrightythen's user avatar

4

Assume that the request is for /index.html.

Your first rewrite condition says «if the URL requested is not a directory, rewrite it with a redirect to itself with an added slash.» So the URL will be rewritten with a redirect to /index.html/. Which will again be rewritten with an added slash, etc ad infinitum. This is why you get the error message.

answered Apr 14, 2013 at 17:44

Jenny D's user avatar

Jenny DJenny D

27.5k21 gold badges74 silver badges112 bronze badges

1

In case future folks stumble across this…

I had a similar problem, where my Laravel 5.1 project was giving 500 errors on the browser and Request exceeded the limit of 10 internal redirects due to probable configuration error in the logfile.

I was able to solve it by adding RewriteBase / just after RewriteEngine On in my .htaccess file.

Hopefully this can help someone.

answered Jan 12, 2016 at 12:12

Brendan White's user avatar

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.

Order allow,deny

# Don’t show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php index.html index.htm

# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_environment_initialize() in
# includes/bootstrap.inc for settings that can be changed at runtime.

# PHP 5, Apache 1 and 2.

php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off

# Requires mod_expires to be enabled.

# Enable expirations.
ExpiresActive On

# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600

# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off

# Various rewrite rules.

RewriteEngine on

# Set «protossl» to «s» if we were accessed via https://. This is used later
# if you enable «www.» stripping or enforcement, in order to ensure that
# you don’t bounce between http and https.
RewriteRule ^ — [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ — [E=protossl:s]

# Make sure Authorization HTTP header is available to PHP
# even when running as CGI or FastCGI.
RewriteRule ^ — [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Block access to «hidden» directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or
# Git to store control files. Files whose names begin with a period, as well
# as the control files used by CVS, are protected by the FilesMatch directive
# above.
#
# NOTE: This only works when mod_rewrite is loaded. Without mod_rewrite, it is
# not possible to block access to entire directories from .htaccess, because
# is not allowed here.
#
# If you do not have mod_rewrite installed, you should remove these
# directories from your webroot or otherwise protect them from being
# downloaded.
RewriteRule «(^|/).» — [F]

# If your site can be accessed both with and without the ‘www.’ prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the ‘www.’ prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the ‘www.’ prefix,
# (http://example.com/… will be redirected to http://www.example.com/…)
# uncomment the following:
# RewriteCond %{HTTP_HOST} .
# RewriteCond %{HTTP_HOST} !^www. [NC]
# RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the ‘www.’ prefix,
# (http://www.example.com/… will be redirected to http://example.com/…)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
# RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /

# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.

# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.*).css $1.css.gz [QSA]

# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.*).js $1.js.gz [QSA]

# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule .css.gz$ — [T=text/css,E=no-gzip:1]
RewriteRule .js.gz$ — [T=text/javascript,E=no-gzip:1]

# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding

Я настраиваю локальную среду через MAMP сайта, который я отключил от сети пару месяцев назад, чтобы просмотреть некоторые старые функции на сайте, и в настоящее время я получаю следующую ошибку в моем файле apache_error.log ,

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., referer: http://localhost:8888/

Я искал решения в других сообщениях (например,
Запрос превысил предел 10 внутренних перенаправлений из-за возможной ошибки конфигурации), и я знаю, что это связано с моим файлом .htaccess. Тем не менее, я не смог выяснить, что не так, потому что мой файл довольно специфичен. Вот оно (я изменил название своего сайта на example.com из соображений конфиденциальности):

Options FollowSymlinks
RewriteEngine On
RewriteRule ^demo/ - [L]
RewriteRule ^.htaccess$ - [F]
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} =""RewriteRule ^.*$ example/public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ example/public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ example/public/index.php [NC,L]

Это может быть длинным выстрелом, но если кто-то может взглянуть и предложить идею о том, что может быть причиной ошибки, я был бы всегда благодарен.

2

Решение

Я сталкивался с этим с большим количеством RewriteRules в моем .htaccess файл. Самое простое, что нужно сделать, это добавить строку в .conf файл для этого домена / сайта, чтобы увеличить предел, так как 10 немного жестко. использование LimitInternalRecursion с последующим большим числом.

Например, у меня есть два сайта:

LimitInternalRecursion 100 (один сайт с множеством правил блокировки)

LimitInternalRecursion 500 (ajax-сайт SSL с большим количеством переадресаций, чтобы заставить вещи делать https вместо http)

Хорошее эмпирическое правило: чем больше RewiteRules, тем выше число, особенно если ваши RewriteRules выполняют много блокировок.

Если вы все еще хотите урезать RewritesRules, я бы пошел (для Apache 2.2):

<FilesMatch ".(htaccess|htpasswd|ini|phps|psd|log|sh|eye)$">
Order Allow,Deny
Deny from all
</FilesMatch>

(Require all denied для Apache 2.4)

вместо RewriteRule ^.htaccess$ - [F] для защиты .htaccess и других файлов (например, .ini, .log, .psd, .sh, .eye и т. д.). Это дает вам больше возможностей для блокировки дополнительных файлов.

ОБНОВИТЬ:

Читая сегодня документы Apache для чего-то другого, я узнал, что LimitInternalRecursion будет принимать два числовых значения, первое число для максимального количества перенаправлений, второе для «насколько глубоко вложенные запросы могут быть вложенными» (читайте дальше LimitInternalRecursion), что-то вроде:

LimitInternalRecursion 100 20

будет лучше настроить директиву.

При наличии только одного числа Apache принимает это число для обоих значений, поэтому:

LimitInternalRecursion 500

Apache будет читать как:

LimitInternalRecursion 500 500

что немного экстрим …

0

Другие решения

Других решений пока нет …

Понравилась статья? Поделить с друзьями:
  • Request error read econnreset радмир
  • Request error getaddrinfo radmir
  • Request error getaddrinfo enotfound
  • Request error character name is wrong перевод
  • Request does not match any route pocketbook как исправить