I must admit, my first reaction was excitement because this is the first time that check I added has come in useful. Anyway, do you mind if I ask why you are using a rewrite like that one?
The thing is, that rewrite is designed to rewrite /*/* to /api/avatar/*/api/avatar/*. When it doesn't find a file that matches at /api/avatar/*/api/avatar/*, it hits the rewrite again, according to the rules in the build output config that we respect