Add a custom redirect function

This function centralizes injecting query parameters and logging
the redirection.