improve gen_redirect script