Define before using it :).

Also, root_path is set correct, but due to rewriting in append_sid, we need to re-rewrite it.