rewrite with arbitrary template and subfolder support