fix several bugs in rel link rewrite function