handle redirects correctly