Refactor rewrite/non-rewrite request handling in the Environment class