LimitInternalRecursion or .htaccess - apache

I've been tasked with maintaining a website that i do not know much about and every 20 minutes i keep getting this problem in the log file
Request exceeded the limit of 2000 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
My .htaccess file is available here - http://pastebin.com/N4GQx73x
I've even tried a few fixes i found on the net using
RewriteCond %{REQUEST_URI} ^/(stats/|404.php|failed_auth.html|error/).* [NC]
RewriteRule .* - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
To no avail. mod_rewrite is beyond me. However i think it's possibly the following 3 lines that is causing the error but not quite sure which condition is causing it.
(5) strip matching prefix: /var/www2/blogs.*DELETED*.co.za/index.php -> index.php
(4) add subst prefix: index.php -> /index.php
(1) [perdir /var/www2/blogs.*DELETED*.co.za/] internal redirect with /index.php [INTERNAL REDIRECT]
I've gone through as many articles as i could find but i just cannot seem to narrow down the cause
Please help me

Just a note on how i solved it. i updated my existing .htaccess with the standard code that is given to you when setting up the wordpress MU install. No more loops!

Related

Apache 2.4 - transparently redirect to subfolder

I am transparently redirecting every request(html, css, js,...) to a subfolder _site (where my static Jekyll site sits...)
RewriteCond %{REQUEST_URI} !^/_site.*
RewriteRule ^(.*)$ _site/$1 [L]
That basically works. Although I find it rather strange, that I have to use the Rewrite condition, to block iterations:
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if ...
After all, I am using [L] for last, so how come, I end up in recursions?!?
If I try to prevent direct access to the site-folder (like example.com/_site/favicon.ico), be prepending this first line:
RewriteRule ^_site.* - [R=403,NC,L]
RewriteCond %{REQUEST_URI} !^/_site.*
RewriteRule ^(.*)$ _site/$1 [L]
Then, also on legitimate access (example.com/favicon.ico) I get a 403!
Apparently, every request takes another round. The legitimate ones, then in “round 2” match the forbidden rule. So, what's wrong here?
Why doesn't „last“ mean „last“? (did something change, i.e. between Apache 2.2 and 2.4? as quite a few thing changed on .htaccess there...)
Cough, „Last“ doesn't quite mean „last“. It only means
„quit rewriting within this file now, ignore the rest of the lines“.
But it also means
„re-run the whole htaccess-thing with that new (rewritten) url.
(Something you might not notice for YEARS, if your rewrite rules are too specific to trigger recursions... even, if in all honesty, its in the docs)
So, happy recursion, everyone. To truly put an end to things, guess what:
RewriteRule ^(.*)$ _site/$1 [END]
... respectively in my extended version:
RewriteRule ^_site.* - [R=403,NC,END]
RewriteCond %{REQUEST_URI} !^/_site.*
RewriteRule ^(.*)$ _site/$1 [END]
( .. ,L,END doesn't hurt, but END implies L)

rewrite rule failed to work when I moved on a newer Apache version (2.4)

I had a Centos 5 VPS and moved on to Centos 7 with Apache 2.4. I don't know what was my earlier version of Apache on Centos 5 system, but I know that my Rewrite rule worked perfectly.
However when I moved to Apache 2.4 my old rewriting rule stopped working:
Old Rule:
RewriteRule ^(\/[^\.]*)$ /index.php?page=$1 [NC]
Triggers this error in error log:
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.
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.
New Rule I tried which at least make my www.domainname.com to work:
RewriteRule ^([^/]*)$ /index.php?page=$1 [NC]
What is different on Apache 2.4 ? I couldn't find a clue neither here or on Google.
You need to add a RewriteCond that prevents requests to index.php getting rewritten. Two approaches come into mind:
1) only rewrite if the request does not target an existing physical file:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^/?([^/]*)$ /index.php?page=$1 [END]
2) only rewrite if the request does not explicitly target the /index.php location:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule ^/?([^/]*)$ /index.php?page=$1 [END]
The leading ^/? makes sure that this pattern will work in .htaccess style files and in the real http servers host configuration. That makes sense because:
A general hint: you should always prefer to place such rules inside the http servers host configuration instead of using .htaccess style files. Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).

URL Rewrite in .htaccess causing internal 500 error

SOLVED: I've been having an .htaccess rewrite problem with rare cases causing internal 500 errors on my site.
I setup a Rewrite rule in my .htaccess to redirect
http://mysite123.com/churches/ANY_NUMBER_HERE/any_name_here
to
http://mysite123.com/churches.php?churchid=ANY_NUMBER_HERE , but the end-user will still see http://mysite123.com/churches/ANY_NUMBER_HERE/any_name_here
It works perfectly unless they type http://mysite123.com/churches/ANYTHING_BUT_NUMBERS_HERE or if they type numbers without a trailing slash.
This is my rewrite rule:
RewriteRule ^churches\/([0-9]+)\/.*$ /churches.php?church=$1 [L]
Basically, is there a way I can change my rule/regex to make the htacess point to a 404 error page if they type any letters, special symbols, or numbers WITHOUT a trailing slash? I need to avoid the 500 internal server error, it's hurting my SEO
EDIT: I'm getting this error code in the server logs:
[Tue Aug 04 20:48:44 2015] [error] [client 24.107.131.201] 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.
EDIT #2: I solved the problem by adding this rewrite rule that stops loops:
#STOP LOOPS
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
RewriteRule .* - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

Why does this RewriteRule produce infinite recursion?

I am trying to do rather basic URL rewriting but cannot get it running properly.
I want to redirect all requests to wordpress.foobar.com to a local symlinked WordPress installation via my .htaccess file:
RewriteEngine On
RewriteCond %{SERVER_NAME} ^wordpress\.foobar\.com$
RewriteRule ^(.*) /html/wordpress/$1 [L]
While I can perfectly access foobar.com/html/wordpress, visiting wordpress.foobar.com will raise a 500 Internal Server Error.
Apache's error log will contain the following:
[error] [client 12.123.123.123] 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.
When I enable debug LogLevel I can see that Apache is trying to rewrite favicon.ico infinitely, always appending another layer of /html/wordpress/ until the recursion limit is reached.
What's wrong with this rewrite?
Use:
RewriteCond %{SERVER_NAME} ^wordpress\.foobar\.com$
RewriteCond %{REQUEST_URI} !/html/wordpress/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /html/wordpress/$1 [L]
With -f and -d test, you do not redirect existing files and directories. This way, you avoid the problems with favicon.ico (if you have that file, I suggest you add if this is not the case).
When you get the error Request exceeded the limit of 10 internal redirects due to
probable configuration error., ask yourself the question: How did I design my rules to terminate at some point, and why does it not terminate.
In your case, your rule matches everything. The status of the condition will not change either, so if your rule matches one time, it will match an infinite amount of times. This might work on some setups if you rewrite to a file that does exist. It is a safer bet to just prevent it from rewriting more than once by testing if /html/wordpress/ already is in the url:
RewriteCond %{SERVER_NAME} ^wordpress\.foobar\.com$
RewriteCond %{REQUEST_URI} !/html/wordpress/
RewriteRule ^(.*)$ /html/wordpress/$1 [L]
Besides this, I am not sure if wordpress will recognize your rewritten url. That is for you to figure out.

How to avoid Apache mod rewrite endless redirects?

My .htaccess is very simple:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^qmind/themen/([^/]*)/$ /qmind/themen/t/?art=$1 [L]
RewriteRule ^qpodcast/podcasts/([^/]*)/$ /qpodcast/podcasts/?id=$1 [L]
RewriteRule ^qmind/artikel/([^/]*)\/$ /qmind/artikel/?id=$1 [L]
The last two Rules works perfectly but the first one causes an Internal-Error.
Apache shows: Request exceeded the limit of 10 internal redirects due to probable configuration error.
but I can't find my mistake.
Apache Error-Log says also Use 'LogLevel debug' to get a backtrace. but I don't no how.
Thx for help!
RewriteRule ^qmind/themen/([^/]*)/$ /qmind/themen/t/?art=$1 [L]
lets take an example
qmind/themen/test
This runs as
qmind/themen/test
qmind/themen/t/art=test
qmind/themen/t/art=t
and then repearts the bottom one as the URL matches itself
You need to write the rule to accept /t/ as valid and not rewrite it
RewriteRule ^qmind/themen/([^/]*)/$ /qmind/themen/t/index.php?art=$1
should work as it no longer matches the original regex