# URL Shortener Expander - Redirect Checker (`benthepythondev/url-shortener-expander`) Actor

Expand shortened URLs and inspect redirect chains with final URL, status codes, redirect count and intermediate locations.

- **URL**: https://apify.com/benthepythondev/url-shortener-expander.md
- **Developed by:** [Ben](https://apify.com/benthepythondev) (community)
- **Categories:** Automation, SEO tools, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## URL Shortener Expander - Redirect Checker

Expand short links and inspect redirect chains in a structured Apify dataset. Paste shortened URLs, tracking links or any redirected URLs and the actor returns the final destination, HTTP status codes, redirect count, final domain and every intermediate location.

### What is the URL Shortener Expander?

Short links are everywhere: social posts, email campaigns, affiliate links, ad creatives, newsletters, SMS campaigns and customer support messages. They are convenient for sharing, but they hide the final destination. For analytics, compliance, SEO, security checks and campaign QA, you often need to know where a link actually lands.

This actor follows redirects step by step without using a browser. It records each hop so you can see exactly how a link moves from the original URL to the final page. The result is a clean dataset you can export to JSON, CSV or Excel, or connect to automation tools.

### Common use cases

Use this actor to audit social media links, verify affiliate redirects, check email campaign destinations, expand `t.co` links from exported tweets, inspect `bit.ly` links in a dataset, detect broken or suspicious redirects, document redirect chains for SEO migrations, or normalize links before deduplication.

Marketing teams can QA campaign links before launch. SEO teams can spot redirect loops or long redirect chains. Data teams can expand short links before enrichment. Security teams can inspect final domains without manually clicking every URL.

### Input

Provide one or more URLs.

```json
{
  "urls": [
    "https://bit.ly/3Yq8PzP",
    "https://t.co/example"
  ],
  "maxRedirects": 10
}
````

### Output

Each dataset item represents one expanded URL.

```json
{
  "original_url": "https://bit.ly/3Yq8PzP",
  "final_url": "https://example.com/final-page",
  "status_code": 200,
  "redirect_count": 2,
  "redirect_chain": [
    {
      "url": "https://bit.ly/3Yq8PzP",
      "status_code": 301,
      "location": "https://example.com/intermediate"
    },
    {
      "url": "https://example.com/intermediate",
      "status_code": 302,
      "location": "https://example.com/final-page"
    },
    {
      "url": "https://example.com/final-page",
      "status_code": 200,
      "location": null
    }
  ],
  "is_shortener_domain": true,
  "final_domain": "example.com",
  "error": null
}
```

### Output fields

- `original_url` - URL from the input.
- `final_url` - last URL reached after redirects.
- `status_code` - status code of the final request.
- `redirect_count` - number of redirects followed.
- `redirect_chain` - full hop-by-hop redirect trace.
- `is_shortener_domain` - true for common shortener domains such as bit.ly, t.co and tinyurl.com.
- `final_domain` - domain of the final destination.
- `error` - request error, if one occurred.

### Why use this actor?

Redirects are easy to hide and hard to audit manually. This actor makes them visible in a repeatable way. It is lightweight, fast and cheap to run because it does not open a browser. You can run it on a schedule, call it through the Apify API, or plug it into Make, Zapier, n8n and custom data pipelines.

### Example workflows

For social media analysis, export posts that contain short links, pass the URLs into this actor, and group results by `final_domain`. For email marketing QA, expand every tracked link before sending a campaign and catch destinations that point to staging, 404 pages or old redirects. For affiliate operations, inspect redirect chains to confirm that tracking links route through the expected network.

For SEO migrations, use the actor to document redirects after a site move. Long chains can slow crawlers and create unnecessary hops, while broken redirects can leak traffic. The `redirect_chain` field gives you a clear audit trail you can hand to a developer or client.

### Integration ideas

Combine this actor with a sitemap or RSS scraper. First collect URLs from a site, feed, ad library or exported dataset, then expand only the URLs that look shortened or redirected. Send the final URLs into a domain enrichment actor, content scraper or security scanner.

You can schedule recurring checks for important marketing links. If `final_url`, `final_domain` or `status_code` changes, trigger a webhook and alert the responsible team. This is especially useful for paid ads, newsletters, influencer links and partner campaigns where broken links cost money quickly.

### Notes and limits

Some websites block automated requests or vary redirects by geography, device or cookies. The actor returns the redirect chain seen from the Apify run environment. For browser-only landing pages or heavily protected links, final status may differ from what a logged-in user sees. Long redirect chains are capped by `maxRedirects` to avoid loops.

### Best practices

Keep `maxRedirects` at the default unless you are diagnosing loops. Store both the original URL and final URL so you can deduplicate campaigns without losing the raw source. When auditing large datasets, group by `final_domain` and investigate unexpected domains first. If a link returns an error, re-test from a browser before making a final compliance or security decision because some links behave differently with cookies or regional routing.

### FAQ

Does it click links in a browser?

No. It follows HTTP redirects directly. That keeps runs fast and predictable.

Can it detect redirect loops?

It caps redirects using `maxRedirects`, and the chain shows repeated URLs if a loop occurs.

Can I use it for SEO checks?

Yes. Redirect count, final status and redirect chain are useful for migration audits and broken link cleanup.

Can it expand social short links?

Yes, when the shortener allows normal HTTP redirect resolution.

### You might also like

- Sitemap URL Extractor - collect URLs to audit.
- Website Contact Extractor - enrich domains with contact data.
- Robots Sitemap Analyzer - inspect crawl rules and sitemap links.

### Keywords

URL expander, short link expander, redirect checker, redirect chain API, bitly expander, t.co expander, SEO redirect audit, URL unshortener, link checker, Apify URL tool.

# Actor input Schema

## `urls` (type: `array`):

Shortened or redirected URLs to expand.

## `maxRedirects` (type: `integer`):

Maximum number of redirects to follow per URL.

## Actor input object example

```json
{
  "urls": [
    "https://bit.ly/3Yq8PzP"
  ],
  "maxRedirects": 10
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "urls": [
        "https://bit.ly/3Yq8PzP"
    ],
    "maxRedirects": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("benthepythondev/url-shortener-expander").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "urls": ["https://bit.ly/3Yq8PzP"],
    "maxRedirects": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("benthepythondev/url-shortener-expander").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "urls": [
    "https://bit.ly/3Yq8PzP"
  ],
  "maxRedirects": 10
}' |
apify call benthepythondev/url-shortener-expander --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=benthepythondev/url-shortener-expander",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "URL Shortener Expander - Redirect Checker",
        "description": "Expand shortened URLs and inspect redirect chains with final URL, status codes, redirect count and intermediate locations.",
        "version": "1.0",
        "x-build-id": "9Br1qY1rHJbdjnZdf"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/benthepythondev~url-shortener-expander/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-benthepythondev-url-shortener-expander",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/benthepythondev~url-shortener-expander/runs": {
            "post": {
                "operationId": "runs-sync-benthepythondev-url-shortener-expander",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/benthepythondev~url-shortener-expander/run-sync": {
            "post": {
                "operationId": "run-sync-benthepythondev-url-shortener-expander",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "urls": {
                        "title": "URLs",
                        "type": "array",
                        "description": "Shortened or redirected URLs to expand.",
                        "default": [
                            "https://bit.ly/3Yq8PzP"
                        ],
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxRedirects": {
                        "title": "Max redirects",
                        "minimum": 1,
                        "maximum": 30,
                        "type": "integer",
                        "description": "Maximum number of redirects to follow per URL.",
                        "default": 10
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
