Request exceeded the limit of 10 internal redirects due to probable configuration error, Use 'LimitInternalRecursion' to increase the limit

31,259

Rediect www to non-www via virtual host configuration, solved the problem.

<virtualhost> 
     ServerAdmin [email protected] 
     ServerName yoursite.com 
     ServerAlias www.yoursite.com 
     DocumentRoot /var/www/yoursite.com/public_html
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

     # You must your the <directory> container. For more information see     filesystem containers 
     # http://httpd.apache.org/docs/current/sections.html#virtualhost 

     <directory />

    # You more than likely can the remove the <ifModule> container as your Rewrite 
    # Engine is probably turned on in your main server config file 
    # (check here: /etc/apache2/apache2.conf) but it is here for structure. 

    <IfModule mod_rewrite.c>
            Options +FollowSymlinks
            RewriteEngine On
    </IfModule>

    # Redirects WWW URL's to Non-WWW URL's

    <IfModule mod_rewrite.c>
            RewriteCond %{HTTPS} !=on
            RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
            RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
    </IfModule>

     # If there is a specific directory within your Virtual Host that you wanted to 
     # modify, you would have to nest another <directory> container within the root directory
     # of virtual host previously declared with reference to the directory.  

     <directory /some-directory> 
             # your rules would go here.
     </directory>

</directory>

Share:
31,259

Related videos on Youtube

Vineet kharwar
Author by

Vineet kharwar

4+ Years of Experience in Software in agile development methodology. Major work focused on PHP-Mysql, Ajax, jQuery, Java Script, HTML5, CSS3, Node.js, Bootstrap. Large experience in PHP Yii Framework, Wordpress, Drupal &amp; Magento.

Updated on September 18, 2022

Comments

  • Vineet kharwar
    Vineet kharwar over 1 year

    here is my .htaccess for wordpress blog site, using it to redirecting www to non-www

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ http://example.com%{REQUEST_URI} [R=301,L]
    
    RewriteBase /blog/
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html|php)\ HTTP/
    RewriteRule ^(([^/]+/)*)index\.(html|php)$ http://example.com/blog/$1 [R=301,L]
    
    RewriteCond %{REQUEST_URI} /+[^\.]+$
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    

    but when i try to open www.example.com/blog/ it gives 500 internal error.

    in the log it's mention : 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.

    Any suggestion, what is wrong with my .htaccess

    Error Log :

        [Tue Sep 13 08:49:52 2016] [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.
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3072): [client 127.0.0.1] r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /blog
    [Tue Sep 13 08:49:52 2016] [debug] net/instaweb/apache/mod_instaweb.cc(384): [client 127.0.0.1] ModPagespeed OutputFilter called for request /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:52 2016] [debug] net/instaweb/apache/mod_instaweb.cc(405): [client 127.0.0.1] Request not rewritten because: request->status != 200 (was 500)
    [Tue Sep 13 08:49:52 2016] [debug] mod_deflate.c(687): [client 127.0.0.1] Zlib: Compressed 625 to 385 : URL /mnt/var/www/html/example/web/index.php
    [Tue Sep 13 08:49:53 2016] [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., referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3072): [client 127.0.0.1] r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] core.c(3078): [client 127.0.0.1] redirected from r->uri = /favicon.ico, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] net/instaweb/apache/mod_instaweb.cc(384): [client 127.0.0.1] ModPagespeed OutputFilter called for request /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] net/instaweb/apache/mod_instaweb.cc(405): [client 127.0.0.1] Request not rewritten because: request->status != 200 (was 500), referer: http://www.example.com/blog
    [Tue Sep 13 08:49:53 2016] [debug] mod_deflate.c(687): [client 127.0.0.1] Zlib: Compressed 625 to 385 : URL /mnt/var/www/html/example/web/index.php, referer: http://www.example.com/blog
    
    • MrWhite
      MrWhite over 7 years
      "Use 'LogLevel debug' to get a backtrace." - If you have access to the server config, you should try this as this will give you a big clue as to which bit is causing the problem. Are you suggesting it is OK when you request example.com/blog/somepage? I suspect it might have something to do with trying to append a slash?
    • Vineet kharwar
      Vineet kharwar over 7 years
      I tried LogLevel debug but same Internal server error. And this example.com/blog/somepage request gives me error : Request exceeded the limit of 10 internal redirects due to probable configuration error.
    • Vineet kharwar
      Vineet kharwar over 7 years
      thanks, Error log : [Tue Sep 13 08:16:07 2016] [debug] net/instaweb/apache/mod_instaweb.cc(405): [client 127.0.0.1] Request not rewritten because: request->status != 200 (was 500), referer: example.com/blog [Tue Sep 13 08:16:07 2016] [debug] mod_deflate.c(687): [client 127.0.0.1] Zlib: Compressed 625 to 385 : URL /mnt/var/www/html/example/web/index.php, referer: example.com/blog
    • Vineet kharwar
      Vineet kharwar over 7 years
      @w3kd can you make sense of error log ?
    • MrWhite
      MrWhite over 7 years
      You should add the error log snippet to your question (to preserve formatting). There should be more to it than what you've posted. If you are not seeing a full backtrace, then try LogLevel rewrite:trace8 (or even LogLevel trace8) instead.
    • Vineet kharwar
      Vineet kharwar over 7 years
      @w3kd attached error log snippet to question.
    • Unbeliever
      Unbeliever over 7 years
      This is a common problem. particularly with RewriteRules in htaccess files where a URI path gets continually rewritten, hence reaching the internal redirect limit. Most of the time the only real way to debug it is to enable mod_rewrite logging. Details on how you can do this are here: wiki.apache.org/httpd/RewriteLog
    • MrWhite
      MrWhite over 7 years
      @Unbeliever That is what the OP has already done. Incidentally, RewriteLog is for Apache 2.2, the OP is on 2.4.
    • MrWhite
      MrWhite over 7 years
      Where is this .htaccess file - in the document root, or inside the /blog directory itself? What is the actual directory structure? Rather curious that the /blog directory is not mentioned in your log... /mnt/var/www/html/example/web/index.php? Is that the document root?
    • Vineet kharwar
      Vineet kharwar over 7 years
      .htaccess file is in the "/mnt/var/www/html/example/web/blog/.htaaccess" directory and the document root is "/mnt/var/www/html/example/web".
    • Unbeliever
      Unbeliever over 7 years
      @w3dk The link provided shows how to enable logging for mod_rewrite for both apache v2.2 and v2.4. The method is different but the output, and thus the usefulness, remains the same. Far more information can be shown in the log than has been added to the question so far.
    • MrWhite
      MrWhite over 7 years
      You mention that http://www.example.com/blog/ (with a trailing slash) results in a 500 error), but your logs show http://www.example.com/blog (no trailing slash)? Is DirectorySlash Off set in your server config?
    • Vineet kharwar
      Vineet kharwar over 7 years
      @w3dk no DirectorySlash is not set to Off. Can you tell me how to redirect www to non-www via .htaccess or server config ?
    • MrWhite
      MrWhite over 7 years
      That is what your first rule does (redirect www to non-www), although the first condition (ie. RewriteCond %{ENV:REDIRECT_STATUS} ^$) is not required - in fact that could be preventing the redirect from happening (depending on your server config).
    • Jonah Benton
      Jonah Benton over 7 years
      If access to server config is available, this is much more easily done with virtualhosts. Have one virtualhost for the canonical domain, and then a second virtualhost that catches all non canonical domain visits and redirects them to canonical.
    • Vineet kharwar
      Vineet kharwar over 7 years
      @JonahB can you give me an example code for virtualhost ?
    • Vineet kharwar
      Vineet kharwar over 7 years
      @JonahB thanks, virtualhost configuration works for me :). I will Answer the question with virtualhost config.