PHP Developer
PHP Developer

Reputation: 107

AH00124: Request exceeded the limit of 10 internal redirects on APACHE Server

I'm using php 7 on aws for running my php application, it has some decent traffic. However at the end of day i check my apache logs for errors / activity. I find one common thing daily with 10 to 15 lines with same error

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.

However i'm not able to get this error, why does it occur, somehow i got to know that it occurs due to redirect / some rules in .htaccess. I'm not able to get where the logic failure is because it does not give any error on localhost or errors while running any script.

Below is my .htaccess code

<IfModule mod_rewrite.c>
    RewriteEngine On

    # for subdomain like test.example.com to redirect to https://test.example.com
    #RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
    #RewriteCond %{HTTPS} off
    #RewriteCond %{HTTP_HOST} ^([\.\w\-]*)\.(com|in)$ [NC]
    #RewriteRule ^ https://%1.%2%{REQUEST_URI} [R=301,L,NE]

    # We are setting here the default file to load while the URL is called followed by fallback files
    DirectoryIndex index.php

    # Redirect all requests except only POST
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:php?)[\s?/] [NC]
    RewriteRule ^ /%1%2 [R=302,L,NE]

    # Adds a trailing directory if rewritten URI is a direcory
    RewriteCond %{DOCUMENT_ROOT}/app/$1 -d
    RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L]

    # Over here we have set the default root directory now request will be directly made from this directory
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteCond %{REQUEST_URI} !/app/ [NC]
    RewriteRule (.*) /app/$1 [L]

    # over here we're removing .php extensions
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]

    # code to make pretty URLS | we're using this code to achieve /category/slug
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\w-]+)/([\d]+)$ app/post.php?&category=$2&page=$3 [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\w-]+)/([\w-]+)$ app/post.php?&category=$2&slug=$3 [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\d]+)$ app/index.php?page=$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?(.+)/([\w-]+)$ app/post.php?category=$2 [L]

    # we have set here custom error files to handle server errors
    ErrorDocument 404 /app/error_pages/404.php
    ErrorDocument 403 /app/error_pages/403.php
    ErrorDocument 500 /app/error_pages/500.php

    # We are setting here default charset & language headers setting for our website
    AddDefaultCharset UTF-8
    DefaultLanguage en-US

</IfModule>

# --------------------------------------------------- Caching Rules Section ---------------------------------------------------

<IfModule mod_headers.c>
    <filesMatch "\.(woff|otf|eot|opentype|ttf|woff2)$">
        #for a year
        Header set Cache-Control "max-age=31556952, public, must-revalidate"
    </filesMatch>
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
        #for a month
        Header set Cache-Control "max-age=2629746, public, must-revalidate"
    </filesMatch>
    <filesMatch "\.(css|scss|min|min.css)$">
        #for a week
        Header set Cache-Control "max-age=604800, public, must-revalidate"
    </filesMatch>
    <filesMatch "\.(js|min|min.js)$">
        #for 3 days
        Header set Cache-Control "max-age=259200, private, must-revalidate"
    </filesMatch>
    #<filesMatch "\.(x?html?|xml)$">
    #   Header set Cache-Control "private, must-revalidate"
    #</filesMatch>
</IfModule>

# --------------------------------------------------- Caching Rules Section ---------------------------------------------------

Allow from all

# Disable directory browsing
Options All -Indexes

Upvotes: 0

Views: 4901

Answers (1)

Matthieu Racine
Matthieu Racine

Reputation: 11

The problem is that your redirects rules cause an infinite loop. Adding a LimitInternalRecursion clause wil just hide the problem.

First you have to determine what request is responsible of this problem : Check your apache access log lines with return code 500 with the same time stamp than the one found in error log.

Second, you can activate Rewrite Rules logging to debug. See : https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

Upvotes: 1

Related Questions