How to check where a redirect really goes
How can I tell a redirect is happening?
Start with the browser. MDN says that when browsers receive a redirect, they immediately load the new address provided in the Location header1. So type the old address, press enter, and watch the address bar. If it changes to something else, a redirect happened.
That test is quick, but it hides detail. You can't see whether the redirect was permanent or temporary, and you can't see how many hops there were. For that you need to look at the replies themselves.
What's the simplest way to see the replies?
Use curl. It's a free command line tool for fetching web addresses, and its manual is published by the curl project. You type commands into a terminal window. Check the curl project's own pages for how to get it on your computer.
The -I option, also written --head, fetches the headers only2. Headers are the short notes a server sends before the page itself. Here's the manual's own example:
curl -I https://example.com
Swap in your own address. In the output, look for two things. First, the status code. MDN says redirect replies have status codes that start with 31. Second, the Location line, which holds the address the server wants you to go to next1.
What each code means is laid out in the codes explained, which starts from the fact that redirect replies begin with 31.
How do I follow the redirect all the way?
Add -L, also written --location. The curl manual says that if the server reports that the page has moved, this option makes curl redo the request to the new place2. The manual also says that if you use it together with --head, headers from all requested pages are shown2.
curl -I -L https://example.com
Now you'll see a block of headers for each hop. Count the blocks that start with a redirect code. More than one means a chain. If the list never stops, read about loops and long chains.
What if it never ends?
Then you may have a loop. The curl manual says you can limit the redirects curl follows with the --max-redirs option, and that by default the limit is set to 50 redirects2. Its own example is curl --max-redirs 3 --location https://example.com2.
With a low limit, a loop stops quickly and you can see which two addresses keep swapping.
What should I test?
Test the addresses people really use. Google's advice for site moves is short: test the redirects, and check your redirects from the old site to the new one3. For a big list, it points to command line tools or scripts3.
For a small site, a short list covers most of it:
- Your old page addresses, one by one, against the new pages you meant them to reach.
- The plain
http://version of your home page. - The version with
wwwand the version without. - A page that doesn't exist, to see that it shows a proper "not found" page and not a redirect to the home page.
Write down what you expected next to what you got. A redirect that ends on a page that exists can still be the wrong page.
Why did my browser show something different from curl?
Your browser keeps its own stored data, such as a cache and cookies. MDN says that on the visitor's side, a mismatch of cache or cookies can cause a redirect error1. So if a redirect looks wrong in one browser, try a private window, another browser, or curl before you change any rules.
What do I do when the result is wrong?
Change one rule at a time and test again after each change. If you change three things at once, you won't know which one fixed it, or which one made it worse.
If your site is on a platform with its own redirect settings, check those first. They can override or add to rules you wrote yourself. Look at the platform's own help pages for where they sit.
Further reading and sources
- Redirections in HTTP, MDN Web Docs (Mozilla)
- curl manual page, curl project
- Site moves with URL changes, Google Search Central