Limit the number of 301 redirects

Don't perform an external redirect until we are done replacing underscores.

As long as a URL has two (or more) underscores, use internal redirects to
replace each underscore with a dash. Then, when there is only one underscore
left, give the client a 301 redirect to the final URL with all underscores
replaced.