How to Debug and Troubleshoot URL Redirect?

Example of HTTP headers - showing redirect response 304 code
An example of HTTP headers - showing redirect response 304 code (304 Not Modified)
Opened in Firefox Browser, using Network tab.

What is a URL Redirect and Why is it Needed?

A URL redirect is a technique used to automatically forward visitors from one URL to another. When a user or search engine tries to access a specific URL, they are seamlessly sent to a different address instead. Redirects are crucial for maintaining website usability, ensuring smooth transitions when URLs change, and preserving SEO rankings.

 

Common reasons for use of redirects:

Website Migrations: Moving to a new domain while ensuring old links still work.
Fixing Broken or Changed URLs: Redirecting outdated or deleted pages to new locations.
Improving User Experience: Preventing 404 errors and ensuring visitors land on the right content.
SEO Optimization: Preserving search engine rankings by forwarding old pages to relevant new ones.

 

Why would you want to check redirects and can there be a problem with a redirect?

There are many reasons for wanting to check the redirection flow for a specific link or site, some examples include:

  • Validating redirects - Web developers often need to check for redirects when building websites. Checking if redirects respond with a correct code (301,302,304, 307), this can sometimes be a frustrating problem because certain types of redirects like to cache their results which can be hard to clear and ensure things are still behaving as expected.
  • Avoiding malware - It is possible for a redirect to take you from https://www.my-site.com to https://www.not-safe-site.com/ to https://www.other-not-safe-site.com. Checking URLs for redirects before placing or visiting them can uncover unwanted behavior.
  • Discovering redirect loops - Checking redirects can also be useful if you get yourself into a redirect loop. This is the most common issue with redirects that makes sites unavailable.
  • Removing intermediate redirects - Often redirects will redirect to redirects and can be chained many times until browsers give up. Each time a page is requested, additional overhead is created and slows down the total response time. Also multiple or too many redirects affect SEO stats of the site or even can trigger ban from search engines

 

 

There are many different types of redirects, 
the most common HTTP redirect codes:

  • 301 Moved Permanently - This indicates that the page requested has moved permanently. This and all future requests should be directed to the given url. 301 redirects are the preferred redirect type that web developers use for SEO purposes when moving a page to a new location. This tells search engines to give all the value of the old page to the new page.
  • 302 Found - (Previously "Moved temporarily") Tells the client to look at (browse to) another URL. This type of redirect is a little vague, as it indicates that the page requested as found but it is at another location. This type of redirect is often used in place of a temporary redirect where the initial page will likely come back in the future. This is often used when a webpage is under maintenance.
  • 307 Temporary Redirect - In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
  • 304 Not Modified - Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.

 

How do you find the status code of a redirect?

When requesting a webpage, the website will respond with a HTTP status code - this code indicates the redirect type.

Example of HTTP Headers response from the server
HTTP/1.1 301 Moved Permanently
Location: http://www.google.co.uk/
Content-Type: text/html; charset=UTF-8
Cache-Control: public, max-age=2592000

in this line "HTTP/1.1 301 Moved Permanently"  -  301 Moved Permanently is redirect code, 

 

How do you check for redirect and output redirect details?

Checking the redirection details of a URL is easy. You simply enter the initial URL or domain name into the to a request box at many applications after is important to check server response headers that are fallowing your http request.

Obtaining the right information is crucial, otherwise you're surrounded by uncertainty, nothing makes sense, and you get frustrated.

Various of applications and tools can be used for this purpose, bellow will be given few examples of using them.

Output of server responce HTTP Headers - using CURL command
curl -I http://google.co.uk

Just by using <code>curl</code> command, we can output a fill list of https headers from the server for check and debug.
Used in command line (Ubuntu 22.04) 

Full list of HTTP headers response from the server (including redirect header)
HTTP/1.1 301 Moved Permanently
Location: http://www.google.co.uk/
Content-Type: text/html; charset=UTF-8
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-5bYaQoajp_dYDnSDwedr1A' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Date: Mon, 10 Feb 2025 21:04:05 GMT
Expires: Wed, 12 Mar 2025 21:04:05 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 221
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN

Here, in this stack of headers, we can see redirect header and suggested new location to navigate to.

HTTP/1.1 301 Moved Permanently
Location: http://www.google.co.uk/

Having this information is enough to verify, check, confirm defined redirect or redirects on a web server. Ensuring all works as expected and that there is no errors.

 

Conclusion

URL redirects are an essential tool for managing web traffic, ensuring smooth user navigation, and maintaining SEO authority. Choosing the right type of redirect depends on whether the change is permanent (301) or temporary (302/307). Proper implementation helps prevent broken links, enhances user experience, and ensures search engines index the correct pages. With this tutorial, we are now able to debug and troubleshoot redirects.

Tags