I think I see similar code somewhere in registration for downloading which also handle redirection