modified rewrite.js

use jQuery.each