Fix database error when redirect

Merge #19 and close #18