Reset rewrite counter on new request

We were spuriously throwing rewrite limit exceeded for non-looping
rewrites. This patch resets the count to zero at the start of a new
request and adds a test.

COUCHDB-1651
fix make distcheck on linux