title: Rewrite rule causes 'Request exceeded the limit of 10 internal redirects'
body: <p>Why the above line in an <code>.htaccess</code> file causes:</p>
  
  <pre><code>RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&amp;page=$2 [QSA,L]
  </code></pre>
  
  <p>And error in error_log like this:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I found a lot of posts on the Stack Overflow but none of the solutions worked for me. I have a CentOS server with cPanel. This doesn't happen on my server without cPanel.<br>
  Here is my .htaccess file:  </p>
  
  <pre><code>&lt;Files "htaccess_dist"&gt;
      order allow,deny
      deny from all
  &lt;/Files&gt;
  Options -Indexes
  Options +FollowSymLinks
  DirectoryIndex index.php
  &lt;IfModule mod_expires.c&gt;
      ExpiresActive On
      ExpiresDefault "access plus 1 year"
  &lt;/IfModule&gt;
  &lt;FilesMatch "\.(jpg|jpeg|gif|png|mp3|flv|mov|avi|3pg|html|htm|swf|js|css|ico)$"&gt;
      FileETag MTime Size
  &lt;/FilesMatch&gt;
  &lt;IfModule mod_php5.c&gt;   
      php_value memory_limit 64M  
      php_value register_globals 0    
      php_value post_max_size 8388608 
      php_value upload_max_filesize 5242880   
      php_value display_errors 0
  &lt;/IfModule&gt;
  &lt;IfModule mod_gzip.c&gt;
      mod_gzip_on yes
      mod_gzip_dechunk yes
      mod_gzip_keep_workfiles No
      mod_gzip_minimum_file_size 1000
      mod_gzip_maximum_file_size 1000000
      mod_gzip_maximum_inmem_size 1000000
      mod_gzip_item_include mime ^text/.*
      mod_gzip_item_include mime ^application/javascript$
      mod_gzip_item_include mime ^application/x-javascript$
      # Exclude old browsers and images since IE has trouble with this
      mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
      mod_gzip_item_exclude mime ^image/.*
  &lt;/IfModule&gt;
  &lt;IfModule mod_deflate.c&gt;
      AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.[0678] no-gzip
      BrowserMatch \bMSIE !no-gzip
  
  &lt;IfModule mod_headers.c&gt;
      Header append Vary User-Agent env=!dont-vary
  &lt;/IfModule&gt; 
      SetEnvIfNoCase Request_URI action\/* no-gzip dont-vary
      SetEnvIfNoCase Request_URI actions\/* no-gzip dont-vary
  
  &lt;/IfModule&gt;
  &lt;IfModule mod_rewrite.c&gt;
  
  RewriteEngine on
  RewriteBase /
  RewriteRule ^pg\/([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1&amp;%{QUERY_STRING} [L]
  RewriteRule ^pg\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&amp;page=$2&amp;%{QUERY_STRING} [L]
  RewriteRule ^tag\/(.+)\/?$ engine/handlers/page_handler.php?handler=search&amp;page=$1 [L]
  
  
  RewriteRule ^action\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?action=$1&amp;%{QUERY_STRING} [L]
  
  RewriteRule ^cache\/(.*)$ engine/handlers/cache_handler.php?request=$1&amp;%{QUERY_STRING} [L]
  
  RewriteRule ^services\/api\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/service_handler.php?handler=$1&amp;request=$2&amp;%{QUERY_STRING} [L]
  
  RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/?$ engine/handlers/export_handler.php?view=$1&amp;guid=$2 [L]
  RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ engine/handlers/export_handler.php?view=$1&amp;guid=$2&amp;type=$3&amp;idname=$4 [L]
  
  RewriteRule xml-rpc.php engine/handlers/xml-rpc_handler.php [L]
  RewriteRule mt/mt-xmlrpc.cgi engine/handlers/xml-rpc_handler.php [L]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1 [QSA,L]
  
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&amp;page=$2 [QSA,L]
  RewriteRule . /~user/sub/
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>When I add the following to the rules internal redirects stop and the error goes away but css and images don't load:</p>
  
  <pre><code>RewriteCond %{ENV:REDIRECT_STATUS} 200
  RewriteRule ^.* - [L]
  </code></pre>
  
  <p>And here is my httpd.conf file:  </p>
  
  <pre><code>Include "/usr/local/apache/conf/includes/pre_main_global.conf"
  Include "/usr/local/apache/conf/includes/pre_main_2.conf"
  
  
  LoadModule bwlimited_module modules/mod_bwlimited.so
  
  
  Include "/usr/local/apache/conf/php.conf"
  Include "/usr/local/apache/conf/includes/errordocument.conf"
  
  ErrorLog "logs/error_log"
  DefaultType text/plain
  ScriptAliasMatch ^/?controlpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
  ScriptAliasMatch ^/?cpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
  ScriptAliasMatch ^/?kpanel/?$ /usr/local/cpanel/cgi-sys/redirect.cgi
  ScriptAliasMatch ^/?securecontrolpanel/?$ /usr/local/cpanel/cgi-sys/sredirect.cgi
  ScriptAliasMatch ^/?securecpanel/?$ /usr/local/cpanel/cgi-sys/sredirect.cgi
  ScriptAliasMatch ^/?securewhm/?$ /usr/local/cpanel/cgi-sys/swhmredirect.cgi
  ScriptAliasMatch ^/?webmail/?$ /usr/local/cpanel/cgi-sys/wredirect.cgi
  ScriptAliasMatch ^/?whm/?$ /usr/local/cpanel/cgi-sys/whmredirect.cgi
  
  Alias /bandwidth /usr/local/bandmin/htdocs/
  Alias /img-sys /usr/local/cpanel/img-sys/
  Alias /java-sys /usr/local/cpanel/java-sys/
  Alias /mailman/archives /usr/local/cpanel/3rdparty/mailman/archives/public/
  Alias /pipermail /usr/local/cpanel/3rdparty/mailman/archives/public/
  Alias /sys_cpanel /usr/local/cpanel/sys_cpanel/
  
  ScriptAlias /cgi-sys /usr/local/cpanel/cgi-sys/
  ScriptAlias /mailman /usr/local/cpanel/3rdparty/mailman/cgi-bin/
  ScriptAlias /scgi-bin /usr/local/cpanel/cgi-sys/scgiwrap
  
  &lt;Directory "/"&gt;
      Options All
      AllowOverride All
  &lt;/Directory&gt;
  
  &lt;Directory "/usr/local/apache/htdocs"&gt;
      Options Includes Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all    
  &lt;/Directory&gt;
  
  &lt;Files ~ "^error_log$"&gt;
      Order allow,deny
      Deny from all
      Satisfy All
  &lt;/Files&gt;
  
  &lt;FilesMatch "^\.ht"&gt;
      Order allow,deny
      Deny from all
      Satisfy All
  &lt;/FilesMatch&gt;
  
  &lt;IfModule log_config_module&gt;
      LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
      LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
  
      CustomLog "logs/access_log" common
  
      &lt;IfModule logio_module&gt;
          LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  
      &lt;/IfModule&gt;
  
  &lt;/IfModule&gt;
  
  &lt;IfModule alias_module&gt;
      ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
  
  &lt;/IfModule&gt;
  
  &lt;Directory "/usr/local/apache/cgi-bin"&gt;
      AllowOverride None
      Options None
      Order allow,deny
      Allow from all
  &lt;/Directory&gt;
  
  &lt;IfModule mod_log_config.c&gt;
      LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
      LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
      LogFormat "%{Referer}i -&gt; %U" referer
      LogFormat "%{User-agent}i" agent
  
      CustomLog logs/access_log common
  
  &lt;/IfModule&gt;
  
  &lt;IfModule mime_module&gt;
      TypesConfig conf/mime.types
      AddType application/x-compress .Z
      AddType application/x-gzip .gz .tgz
  
  &lt;/IfModule&gt;
  PidFile logs/httpd.pid
  LockFile logs/accept.lock
  Listen 0.0.0.0:80
  Listen [::]:80
  User nobody
  Group nobody
  ExtendedStatus On
  ServerAdmin user@gmail.com
  ServerName wdsl.saptik.com
  LogLevel debug
  
  # These can be set in WHM under 'Apache Global Configuration'
  Timeout 300
  
  ServerSignature On
  
  &lt;IfModule prefork.c&gt;
  
  &lt;/IfModule&gt;
  &lt;IfModule itk.c&gt;
  
  &lt;/IfModule&gt;
  
  RewriteEngine on
  RewriteMap LeechProtect prg:/usr/local/cpanel/bin/leechprotect
  RewriteLock /usr/local/apache/logs/rewrite_lock
  
  # Set UserDir directory for all virtual hosts, except..
  UserDir public_html
  # when the following two modules are loaded
  &lt;IfModule mod_ruid2.c&gt;
  UserDir disabled
  &lt;/IfModule&gt;
  &lt;IfModule itk.c&gt;
  UserDir disabled
  &lt;/IfModule&gt;
  
  # DirectoryIndex is set via the WHM -&gt; Service Configuration -&gt; Apache Setup -&gt; DirectoryIndex Priority
  DirectoryIndex index.html.var index.htm index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml default.htm default.html home.htm index.php5 Default.html Default.htm home.html
  
  # SSLCipherSuite can be set in WHM under 'Apache Global Configuration'
  
  SSLPassPhraseDialog  builtin
  SSLSessionCache         dbm:/usr/local/apache/logs/ssl_scache
  SSLSessionCacheTimeout  300
  SSLMutex  file:/usr/local/apache/logs/ssl_mutex
  SSLRandomSeed startup builtin
  SSLRandomSeed connect builtin
  
      Listen 0.0.0.0:443
      Listen [::]:443
      AddType application/x-x509-ca-cert .crt
      AddType application/x-pkcs7-crl .crl
  
  
  AddHandler cgi-script .cgi .pl .plx .ppl .perl
  AddHandler server-parsed .shtml
  AddType text/html .shtml
  AddType application/x-tar .tgz
  AddType text/vnd.wap.wml .wml
  AddType image/vnd.wap.wbmp .wbmp
  AddType text/vnd.wap.wmlscript .wmls
  AddType application/vnd.wap.wmlc .wmlc
  AddType application/vnd.wap.wmlscriptc .wmlsc
  
  &lt;Location /whm-server-status&gt;
      SetHandler server-status
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1 ::1
  &lt;/Location&gt;
  
  
  
  # SUEXEC is supported
  
  Include "/usr/local/apache/conf/includes/pre_virtualhost_global.conf"
  Include "/usr/local/apache/conf/includes/pre_virtualhost_2.conf"
  
  # DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
  NameVirtualHost 0.0.0.0:80
  NameVirtualHost 127.0.0.1:80
  NameVirtualHost *
  # DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
  
  &lt;VirtualHost 0.0.0.0:80&gt;
      ServerName 0.0.0.0
      DocumentRoot /usr/local/apache/htdocs
      ServerAdmin user@gmail.com
      &lt;IfModule mod_suphp.c&gt;
          suPHP_UserGroup nobody nobody
      &lt;/IfModule&gt;
  &lt;/VirtualHost&gt;
  
  
  # Default vhost for unbound IPs
  
  &lt;VirtualHost *&gt;
      ServerName wdsl.adomain.com
      DocumentRoot /usr/local/apache/htdocs
      ServerAdmin user@gmail.com
      &lt;IfModule mod_suphp.c&gt;
          suPHP_UserGroup nobody nobody
      &lt;/IfModule&gt;
  &lt;/VirtualHost&gt;
  
  # DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
  
  
  # SSL
  
  
  
  
  
  # CPANEL/WHM/WEBMAIL/WEBDISK PROXY SUBDOMAINS
  
  &lt;VirtualHost 0.0.0.0:80 127.0.0.1:80&gt;
      ServerName wdsl.adomain.com
  
      ServerAlias cpanel.* whm.* webmail.* webdisk.*
  
      DocumentRoot /usr/local/apache/htdocs
      ServerAdmin user@gmail.com
      &lt;IfModule mod_suphp.c&gt;
          suPHP_UserGroup nobody nobody
      &lt;/IfModule&gt;
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^cpanel\.
      RewriteRule ^/(.*) http://127.0.0.1:2082/$1 [P]
  
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^webmail\.
      RewriteRule ^/(.*) http://127.0.0.1:2095/$1 [P]
  
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^whm\.
      RewriteRule ^/(.*) http://127.0.0.1:2086/$1 [P]
  
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^webdisk\.
      RewriteRule ^/(.*) http://127.0.0.1:2077/$1 [P]
  
      UseCanonicalName Off
  &lt;/VirtualHost&gt;
  
  
  
  
  
  
  # CPANEL/WHM/WEBMAIL/WEBDISK PROXY SUBDOMAINS
  
  &lt;VirtualHost 0.0.0.0:443 127.0.0.1:443&gt;
      ServerName wdsl.adomain.com
  
      ServerAlias cpanel.* whm.* webmail.* webdisk.*
  
      DocumentRoot /usr/local/apache/htdocs
      ServerAdmin user@gmail.com
      &lt;IfModule mod_suphp.c&gt;
          suPHP_UserGroup nobody nobody
      &lt;/IfModule&gt;
      RewriteEngine On
      &lt;IfModule mod_ssl.c&gt;
          SSLEngine on
          SSLProxyEngine On
              SSLCertificateFile /var/cpanel/ssl/cpanel/cpanel.pem
          SSLCertificateKeyFile /var/cpanel/ssl/cpanel/cpanel.pem
          SSLCertificateChainFile /var/cpanel/ssl/cpanel/cpanel.pem
  
      &lt;/IfModule&gt;
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^cpanel\.
      RewriteCond %{HTTPS} on
      RewriteRule ^/(.*) https://127.0.0.1:2083/$1 [P]
  
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^webmail\.
      RewriteCond %{HTTPS} on
      RewriteRule ^/(.*) https://127.0.0.1:2096/$1 [P]
  
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^whm\.
      RewriteCond %{HTTPS} on
      RewriteRule ^/(.*) https://127.0.0.1:2087/$1 [P]
  
      RewriteCond %{HTTP_HOST} !^wdsl.adomain.com$
      RewriteCond %{HTTP_HOST} ^webdisk\.
      RewriteCond %{HTTPS} on
      RewriteRule ^/(.*) https://127.0.0.1:2078/$1 [P]
  
      UseCanonicalName Off
  &lt;/VirtualHost&gt;
  
  #JK
  
  LoadModule jk_module modules/mod_jk.so
  JKWorkersFile /usr/local/apache/conf/workers.properties
  # Where to put jk logs
  JKLogLevel debug
  # Select the log format
  JKLogStampFormat "[%a %b %d %H:%M:%S %Y]"
  # JKOptions indicate to send SSL KEY SIZE
  JKOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
  # JKRequestLogFormat set the request format
  JKRequestLogFormat "%w %V %T"
  # Send all xhtml requests to Glassfish
  JKMount /*.xhtml worker1
  # Send all domain requests to Glassfish
  JKMount /domain/* worker1
  
  &lt;VirtualHost 0.0.0.0:80&gt;
      ServerName sub.domain.com
      ServerAlias www.sub.domain.com
      DocumentRoot /home/sub/public_html/sub
      ServerAdmin webmaster@sub.domain.com
      UseCanonicalName Off
      CustomLog /usr/local/apache/domlogs/sub.domain.com combined
      CustomLog /usr/local/apache/domlogs/sub.domain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
      ## User user # Needed for Cpanel::ApacheConf
      UserDir enabled user
      &lt;IfModule mod_suphp.c&gt;
          suPHP_UserGroup user user
      &lt;/IfModule&gt;
      &lt;IfModule !mod_disable_suexec.c&gt;
          &lt;IfModule !mod_ruid2.c&gt;
              SuexecUserGroup user user
          &lt;/IfModule&gt;
      &lt;/IfModule&gt;
      &lt;IfModule mod_ruid2.c&gt;
          RMode config
          RUidGid user user
      &lt;/IfModule&gt;
      &lt;IfModule itk.c&gt;
          # For more information on MPM ITK, please read:
          #   http://mpm-itk.sesse.net/
          AssignUserID user user
      &lt;/IfModule&gt;
      ScriptAlias /cgi-bin/ /home/user/public_html/sub/cgi-bin/
  
      AccessFileName .htaccess
  &lt;/VirtualHost&gt;
  
  
  &lt;VirtualHost 0.0.0.0:80&gt;  
    ServerAdmin admin@domain.com  
    ServerName  domain.com  
  
          ProxyRequests Off  
          &lt;Proxy *&gt;  
             Order deny,allow  
             Allow from all  
          &lt;/Proxy&gt;
          ProxyPass / http://0.0.0.0:8080/  
          ProxyPassReverse / http://0.0.0.0:8080/  
  
          &lt;Location /&gt;
          Order allow,deny
          Allow from all
          &lt;/Location&gt;
  
         ErrorLog logs/glassfish-apache-error_log  
         CustomLog logs/glassfish-apache-access_log common      
  &lt;/VirtualHost&gt;
  
  Include "/usr/local/apache/conf/includes/post_virtualhost_global.conf"
  Include "/usr/local/apache/conf/includes/post_virtualhost_2.conf"
  </code></pre>