How to display all URLs in a redirect chain?

How to display all URLs in a redirect chain?
Basic redirect (with code 301 - moved permanently)

Into

URL redirects are a way to automatically send users and search engines from one URL to another. They are commonly used to manage website traffic, maintain SEO rankings, and improve user experience.

 

Redirects are useful in various scenarios, such as:

  • Changing URLs – When a page’s URL is updated, a redirect ensures users still reach the correct content.
  • Fixing Broken Links – Redirects prevent 404 errors by forwarding old or incorrect URLs to valid pages.
  • Domain Changes & Migrations – If a website moves to a new domain, redirects help retain visitors and SEO value.
  • Enforcing HTTPS or WWW Preferences – Redirects ensure all traffic goes to the preferred version of a site.

By properly implementing redirects, websites can maintain usability, improve performance, and ensure visitors always reach the right destination.

 

When building new site, maintaining existing one or on attempts to improve SEO for example, very often arise problem of checking redirects, does they configured in a right way? Does they properly redirect and very important question of how many of them? Especial complicated to figure out redirects chain is there is more then 5 redirect in place!
 
This is the main topic of this  how to tutorial, show methods to debug and show redirects details for given url.

 

Solution 1:

This solution to show redirects chain is based of use CURL command that will be set to show detailed output of a request to desired host, the output of a command will be filtered to display redirects what were used during connection phase.
Example executed in Ubuntu 22.04 operation system.
 

Use of CURL command in Ubuntu terminal to display redirects chain.
curl -v -L http://google.co.uk 2>&1 | egrep "^> (Host:|GET)"

CURL command is used, to show redirects for given Url "http://google.co.uk"

Outputed redirets chain using CURL
List of redirects from CURL output

 

Solution 2:

Similar to Solution 1, but used Wget command to get same result, a list of used redirect to new url destination.
Example executed in Ubuntu 22.04 operation system.
 

Use of WGET command in Ubuntu terminal to display redirects chain.
wget -S --max-redirect=5 --spider http://google.co.uk 2>&1 | grep -i "location"

WGET command is used, to show redirects for given Url "http://google.co.uk"

 

Solution 3:

Another way to show all redirects that are happening on connection phase is to output detailed report. We can done this by using http command (HTTPie). 
In outputted information, we need to check "Location" header - what line will indicate the redirect (new location of the page).

http (HTTPie) - command in to available by default, so need to be installed sudo snap install httpie

Output HTTP connection information with http command
http -v -h -F http://google.co.uk

Output of connection details (HTTP headers) using http command (HTTPie)

HTTPie - modern, user-friendly command-line HTTP client for the API era.
 

Example of an output HTTP headers from use of http command
Output HTTP headers using http command

 

Conclusion

URL redirects are essential for maintaining website functionality, improving user experience, and preserving SEO rankings. Knowing way how to check and debug them is essential for keeping your site in a good state and accessible.