Site icon DataForSEO

What are redirect chains and loops and how to check them with On-Page API?

Redirect chains occur when there are at least two redirects between the initial URL and the destination URL. For example, if page A redirects to page B which redirects to page C, such a series of redirects is considered a redirect chain.

Sometimes, if page B redirects back to page A, the redirect chain becomes closed and is considered a redirect loop.

First off, if a visitor or a search engine bot gets to a page through multiple redirects, it takes longer before the destination URL is loaded harming the user experience. Secondly, redirect chains may cause indexing issues and link equity loss. It’s always better to point your redirects straight to the destination URL without any additional hops.

When your redirect chain forms an infinite cycle (a loop), the situation is even worse as it prevents visitors and crawlers from seeing any meaningful content other than the ERR_TOO_MANY_REDIRECTS.

To help you easily find and fix redirect chains and loops, we’ve prepared this short step-by-step guide based on DataForSEO On-Page API.

Before you can jump on to making an API call, remember to register and get your API credentials for authentication.

Learn more about Authentication in our docs >>

Once you’re ready with that, follow the steps below.

1 Set a task to On-Page API.

POST: https://api.dataforseo.com/v3/on_page/task_post

[
  {
    "target": "dataforseo.com",
    "max_crawl_pages": 10,
    “load_resources”: true,
    "tag": "some_string_123",
    "pingback_url": "https://your-server.com/pingscript?id=$id&tag=$tag"
  }
]

2 Call the Summary endpoint to review collective stats for the website.

GET: https://api.dataforseo.com/v3/on_page/summary/$id

In the "results" array, find the "redirect_chain" and "redirect_loop" counters. If they show values greater than 0, our crawler spotted the indicated number of redirect chains and/or loops on the target website.

3 Next, you can call the Redirect chains endpoint. It will provide you with a full list of pages that form a redirect chain. You will get both the source and the destination URL indicated for each URL in a chain.

If you want to review redirect loops only, you should add the following filter to the body of your request: ["is_redirect_loop","=","true"].

POST: https://api.dataforseo.com/v3/on_page/redirect_chains

[
  {
    "id": "03051327-4536-0216-1000-3b458a2cfcca",
    "url": "https://test_rdr.dataforseo.com/a/"
  }
]

Results sample:

{
  "version": "0.1.20210622",
  "status_code": 20000,
  "status_message": "Ok.",
  "time": "2.9408 sec.",
  "cost": 0,
  "tasks_count": 1,
  "tasks_error": 0,
  "tasks": [
    {
      "id": "07061451-2692-0216-1000-33d5e1cf58cd",
      "status_code": 20000,
      "status_message": "Ok.",
      "time": "2.8536 sec.",
      "cost": 0,
      "result_count": 1,
      "path": [
        "v3",
        "on_page",
        "redirect_chains"
      ],
      "data": {
        "api": "on_page",
        "function": "redirect_chains",
        "url": "https://test_rdr.dataforseo.com/a/"
      },
      "result": [
        {
          "crawl_progress": "finished",
          "crawl_status": {
            "max_crawl_pages": 5,
            "pages_in_queue": 0,
            "pages_crawled": 5
          },
          "total_items_count": 1,
          "items_count": 1,
          "items": [
            {
              "is_redirect_loop": false,
              "chain": [
                {
                  "type": "redirect",
                  "domain_from": "test_rdr.dataforseo.com",
                  "domain_to": "test_rdr.dataforseo.com",
                  "page_from": "/a/",
                  "page_to": "/b/",
                  "link_from": "https://test_rdr.dataforseo.com/a/",
                  "link_to": "https://test_rdr.dataforseo.com/b/",
                  "dofollow": true,
                  "page_from_scheme": "https",
                  "page_to_scheme": "https",
                  "direction": "internal",
                  "is_broken": false,
                  "is_link_relation_conflict": false
                },
                {
                  "type": "redirect",
                  "domain_from": "test_rdr.dataforseo.com",
                  "domain_to": "test_rdr.dataforseo.com",
                  "page_from": "/b/",
                  "page_to": "/c/",
                  "link_from": "https://test_rdr.dataforseo.com/b/",
                  "link_to": "https://test_rdr.dataforseo.com/c/",
                  "dofollow": true,
                  "page_from_scheme": "https",
                  "page_to_scheme": "https",
                  "direction": "internal",
                  "is_broken": false,
                  "is_link_relation_conflict": false
                },
                {
                  "type": "redirect",
                  "domain_from": "test_rdr.dataforseo.com",
                  "domain_to": "test_rdr.dataforseo.com",
                  "page_from": "/c/",
                  "page_to": "/test_chain.html",
                  "link_from": "https://test_rdr.dataforseo.com/c/",
                  "link_to": "https://test_rdr.dataforseo.com/test_chain.html",
                  "dofollow": true,
                  "page_from_scheme": "https",
                  "page_to_scheme": "https",
                  "direction": "internal",
                  "is_broken": false,
                  "is_link_relation_conflict": false
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Exit mobile version