1

Today I checked my Apache error.log and I found many:

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.

...mostly from Bing bot.

So i traced the error to my access log and I found that these errors are being caused by some site/bots requesting a file that no longer exists. Which should create 404 (not found) error, but instead it is redirecting the site to look somewhere else and then that place is telling it to look in the first place, causing an internal redirect which only stops once it reaches the maximum of 10 internal redirects. At this point it puts out a 500 internal error and it's crawled over again and again.

Subdomains are in:

/home/html/myname/public_html/_sub/thisisasubdomain/

Resulting domain is:

thisisasubdomain.myname.com

When I try to access a non existing directory in the _sub directory, then I get the 500 error/Request exceeded error.

My VPS has pre-installed server with this rewrite.conf, defined in :

RewriteEngine On
RewriteMap lowercase int:tolower

RewriteCond  %{REQUEST_URI}  !^/webmail(/|$)?
RewriteCond  %{REQUEST_URI}  !^/horde(/|$)?
RewriteCond  %{REQUEST_URI}  !^/roundcube(/|$)?
RewriteCond  %{REQUEST_URI}  !^/setup(2|-new)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/webftp(1|2)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/(db|pg)admin(/|$)?

RewriteCond ${lowercase:%{SERVER_NAME}} ^([0-9a-z-]+)\.([0-9a-z]+)$
RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
RewriteRule ([0-9a-z-]+)\.([0-9a-z]+)/(.*) /home/html/$1\.$2/public_html/$3

RewriteCond  %{REQUEST_URI}  !^/webmail(/|$)?
RewriteCond  %{REQUEST_URI}  !^/horde(/|$)?
RewriteCond  %{REQUEST_URI}  !^/roundcube(/|$)?
RewriteCond  %{REQUEST_URI}  !^/setup(2|-new)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/webftp(1|2)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/(db|pg)admin(/|$)?

RewriteCond ${lowercase:%{SERVER_NAME}} ^www\.([0-9a-z-]+)\.([0-9a-z]+)$
RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
RewriteRule www\.([0-9a-z-]+)\.([0-9a-z]+)/(.*) /home/html/$1\.$2/public_html/$3

RewriteCond  %{REQUEST_URI}  !^/webmail(/|$)?
RewriteCond  %{REQUEST_URI}  !^/horde(/|$)?
RewriteCond  %{REQUEST_URI}  !^/roundcube(/|$)?
RewriteCond  %{REQUEST_URI}  !^/setup(2|-new)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/webftp(1|2)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/(db|pg)admin(/|$)?

RewriteCond ${lowercase:%{SERVER_NAME}} !^www\.([0-9a-z-]+)\.([0-9a-z]+)$
RewriteCond ${lowercase:%{SERVER_NAME}} ^([0-9a-z-]+)\.([0-9a-z-]+)\.([0-9a-z]+)$ 
RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
RewriteRule ([0-9a-z-]+)\.([0-9a-z-]+)\.([0-9a-z]+)/(.*) /home/html/$2\.$3/public_html/_sub/$1/$4

RewriteCond  %{REQUEST_URI}  !^/webmail(/|$)?
RewriteCond  %{REQUEST_URI}  !^/horde(/|$)?
RewriteCond  %{REQUEST_URI}  !^/roundcube(/|$)?
RewriteCond  %{REQUEST_URI}  !^/setup(2|-new)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/webftp(1|2)?(/|$)?
RewriteCond  %{REQUEST_URI}  !^/(db|pg)admin(/|$)?

RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)\.([0-9a-z-]+)\.([0-9a-z-]+)\.([0-9a-z]+)$ 
RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
RewriteRule (.+)\.([0-9a-z-]+)\.([0-9a-z-]+)\.([0-9a-z]+)/(.*) /home/html/$3\.$4/public_html/_sub/$2/$5

Any help is appreciated.

  • 1
    "...with this .htaccess" - Those directives can't be from your .htaccess file?! The RewriteMap directive is not permitted in a directory (or .htaccess) context - this alone would result in a 500 error (if processed). But also you can't rewrite to a filesystem path in .htaccess (which is what all these RewriteRule directives are doing). These directives would only work at all in a server config (or virtual host) context? What should be served in the case of a 404? How should this be served? Do you have a custom 404 ErrorDocument defined somewhere? – MrWhite Nov 30 '17 at 16:59
  • @MrWhite makes some great points! As well, the request path for the missing pages likely matches one of these patterns (without looking closely). It would be helpful to have an example request URL. Add to this, it seems your web host does not know what they are doing. That said, my suggestion is to run away as fast as you can! Find another host. Cheers!! – closetnoc Nov 30 '17 at 17:04
  • 1
    It might help to put the "last" flag [L] on some of your rewrite rules (the ones with /home/html). It doesn't look like you expect multiple of those rules to match. – Stephen Ostermiller Nov 30 '17 at 17:31
  • 1
    Instead of repeating your conditions to ignore certain things it is easier to take care of them upfront by putting in a rewrite rule say "don't rewrite this, and this is the last rule that applies to it:" RewriteRule ^/webmail(/|$)? - [L] – Stephen Ostermiller Nov 30 '17 at 17:33
  • If those conditions are for things that are physical files and directories, you could change your rewrite conditions to RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d which would be a lot simpler. – Stephen Ostermiller Nov 30 '17 at 17:35
1

You've not yet included enough information in your question in order to give a precise answer. (ie. As requested in comments... what should be served in the case of a 404, how this is being served and whether you have a custom 404 ErrorDocument defined somewhere?) You only appear to have included your rewrite directives in your question.

A common cause for a rewrite loop (500 error) when a 404 occurs is because your custom error document is being rewritten (by your mod_rewrite directives) when a 404 occurs. This appears to be what you are describing, but you've not actually stated what is being rewritten.

When you have a custom error document defined, an internal subrequest is triggered that serves this error document. However, this subrequest can also be rewritten by your mod_rewrite directives and essentially "break" the request.

It is common to have to include an exception for your error documents at the top of your mod_rewrite directives. For example:

RewriteRule ^/?error-documents/ - [L]

(Assuming all your error documents are stored in a directory /error-documents in the document root.)

Alternatively, you can prevent the conflicting RewriteRule directive from being triggered on subrequests by using the NS (nosubreq) flag.

Or, remove your custom error document completely (probably not desirable) either by removing the directive where this is defined, or setting ErrorDocument 404 default in a directory (or .htaccess) context if you don't have access to the server config.

  • I checked config on the server (/etc/apache2/ , public_html/, _sub/, _sub/subdomain/), there is no ErrorDocument defined. In my public_html/ I have a .htaccess with some URL rewrite rules, but it's only affects the primary domain (xy.com/index.php?page=1 -> xy.com/page/1). In this path I serve 404 page from Opencart itself with a 404 header. This part is working without problem. Back to subdomains: I tried to access a subdomain which exists, but with a non-existing link and I get a proper default Apache2 404 page (exists.domain.com/notexists.html). – user66638 Nov 30 '17 at 20:28
  • Ah, there is no 404 in your logs at all? Your logs should show the series of internal rewrites that results in the loop (although you might need to change the LogLevel - assuming you're on Apache 2.4+). Can you give an example of a complete URL that triggers a 500 error? – MrWhite Nov 30 '17 at 22:20
  • Nope, no 404 in the logs - pastebin.com/1xG7QKmA. Server is Apache 2.2. Yesterday I turned on loglevel with: RewriteLogLevel 3 RewriteLog "/usr/local/var/apache/logs/rewrite.log". This is it? But I didn't understand much from it so I turned off. If it helps I can turn it on again for a test. Non existing subdomain: miez.mihalko.eu. Working subdomain: opencart.mihalko.eu. Working subdomain with non existing content (404 page): opencart.mihalko.eu/test. – user66638 Nov 30 '17 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.