automatically detect rewrite base