# Sitemap Checker: Broken Links, 404s & Redirects for Every URL (`codesidian/sitemap-url-health-checker`) Actor

Sitemap checker and sitemap URL extractor. Give it a site or sitemap URL: it discovers all sitemaps (robots.txt, indexes, .xml.gz), lists every URL, and checks each for 404s, broken links, redirect chains and slow responses. $1 per 1,000 URLs checked; network failures are free.

- **URL**: https://apify.com/codesidian/sitemap-url-health-checker.md
- **Developed by:** [J Latham](https://apify.com/codesidian) (community)
- **Categories:** SEO tools, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 50.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

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/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Sitemap Checker: Broken Links, 404s & Redirects for Every URL

**Sitemap Checker** takes a website or a sitemap URL, discovers all of its sitemaps (via `robots.txt`, `/sitemap.xml`, sitemap indexes and `.xml.gz` files), and checks every URL in them for broken links (404/5xx), redirect chains, slow responses and wrong content types. You get one dataset row per URL plus a `SUMMARY` with counts and the full list of broken and redirected URLs. Prefer to just collect the URLs? Switch off `checkUrls` and it works as a **sitemap URL extractor**, returning every URL with its `lastmod` for $0.0002 each.

**What it costs:** $0.001 per URL that returns an HTTP response ($1 per 1,000), or $0.0002 per URL in list-only mode. Network failures are free, and the run stops cleanly at your maximum-charge limit.

**Polite by design:** at most 2 requests per host in flight, `Crawl-delay` from `robots.txt` honoured, same-site URLs only by default, and private/internal addresses refused.

### What it does

1. **Discovery** – for a site URL: `Sitemap:` lines in `robots.txt`, then `/sitemap.xml` and `/sitemap_index.xml` if robots lists none. A direct sitemap URL (`.xml`, `.xml.gz`, `.txt`) is used as-is.
2. **Parsing** – `<urlset>` and `<sitemapindex>` (recursive, depth ≤ 4, ≤ 500 sitemap files per input), gzip detected by content, plain-text sitemaps, `lastmod` captured. Malformed XML is tolerated: everything parseable/recoverable is kept and the sitemap is flagged `malformed` in `SUMMARY`. Entity declarations and decompression bombs are rejected.
3. **Checking** (optional) – `HEAD`, falling back to `GET` (body never downloaded) when HEAD fails or answers 4xx/5xx other than 429. Records status, final URL, redirect-chain length and hops, response time, content type.

### Input

| Field | Description |
|---|---|
| `urls` | Site URLs or sitemap URLs, one per line. |
| `checkUrls` | `true` (default): check each URL. `false`: list sitemap URLs only. |
| `maxUrls` | Max URLs **per input** (default 100, up to 100 000). Large indexes are read only as far as needed. |
| `includeExternalHosts` | Default `false`: only URLs on the same site as the input (ignoring `www.`) are processed, so a sitemap can't make the Actor probe third parties. |
| `useGetFallback` | Default `true`. |
| `maxConcurrency` | Total parallel checks (default 10). **At most 2 requests per host** are ever in flight. |
| `maxCrawlDelaySecs` | `Crawl-delay` from `robots.txt` (our user-agent group, else `*`) is honoured between request starts per host, capped at this value (default 10; 0 disables). |
| `timeoutSecs` | Per-request timeout (default 20). |

Private/loopback/link-local targets are refused (SSRF guard); redirects are guarded too.

### Output

Dataset item per URL:

```json
{"url":"https://ghost.org/contact/","lastmod":"2025-08-04T02:01:27-06:00","sitemap":"https://ghost.org/sitemap-pages.xml",
 "source":"https://ghost.org","checked":true,"statusCode":200,"statusClass":"2xx","finalUrl":"https://ghost.org/contact/",
 "redirectCount":0,"redirectChain":[],"responseTimeMs":43,"contentType":"text/html; charset=UTF-8","method":"HEAD",
 "error":null,"errorType":null,"checkedAt":"2026-11-21T11:15:18+00:00"}
```

Network failures have `statusCode: null`, `statusClass: "error"` and an `errorType` (`timeout`, `connection_error`, `tls_error`, `dns_error`, `blocked_target`, …). An input with no usable sitemap yields one item with `errorType: "no_sitemap"`.

`SUMMARY` (key-value store): `countsByStatusClass` (2xx/3xx/4xx/5xx/error), `brokenCount` + `broken` list (4xx/5xx/network errors, capped at 1000), `redirectedCount` + `redirected`, per-input sitemap report (files read, kinds, URL counts, malformed flags, errors, truncation), charged events, URLs skipped due to the max-charge limit.

### Pricing (pay per event)

- **`url-checked` – $0.001** per URL that returned an HTTP response (any status, 404/500 included). Failed network checks are free.
- **`url-listed` – $0.0002** per URL when `checkUrls` is off (listing only).
- Discovery (robots/sitemap fetches) and error items are free. Charges use idempotency keys per URL, and the run stops cleanly at your maximum total charge (remaining URLs listed in `SUMMARY`).

### Develop & test

```bash
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt pytest
.venv/bin/python -m pytest -q                 # offline suite (fixtures + mock transport, incl. end-to-end under PPE test mode)
## local run
mkdir -p storage/key_value_stores/default
echo '{"urls":["https://ghost.org"],"maxUrls":30}' > storage/key_value_stores/default/INPUT.json
ACTOR_TEST_PAY_PER_EVENT=true APIFY_LOCAL_STORAGE_DIR=$PWD/storage .venv/bin/python -m src
```

Local PPE test mode bills every event at $1 (including the SDK's synthetic `apify-default-dataset-item`); this is a local artifact only. The charging log is in `storage/datasets/charging-log`.

### Known limitations

- `robots.txt` `Disallow` rules are not applied to checks (only `Crawl-delay`); sitemap URLs are checked because the site owner published them.
- No JavaScript rendering; bot-protected sites may answer 403/429 to HEAD/GET (reported as such, and charged as a response).
- `maxUrls` is per input; cross-input duplicates are removed.

### Related Actors

- [Website Technology Detector](https://apify.com/codesidian/website-tech-profiler): profile the technology stack (CMS, frameworks, analytics, CDN) of any list of sites.

# Actor input Schema

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

Website URLs (sitemaps are discovered automatically) or direct sitemap URLs (.xml, .xml.gz, .txt), one per line.

## `checkUrls` (type: `boolean`):

On: send a HEAD request (GET fallback) to every URL and record status, redirects, timing and content type ($0.001 per URL that answers). Off: only list the sitemap URLs with their lastmod ($0.0002 per URL).

## `maxUrls` (type: `integer`):

Upper bound of URLs taken from each site/sitemap input. Sitemap files are read only as far as needed.

## `includeExternalHosts` (type: `boolean`):

By default only URLs on the same site as the input (ignoring a leading www.) are processed, so a sitemap cannot make the Actor probe third-party hosts. Enable to process every URL listed.

## `useGetFallback` (type: `boolean`):

When HEAD fails or returns a 4xx/5xx other than 429, retry once with GET (the body is not downloaded). Many servers answer HEAD incorrectly.

## `maxConcurrency` (type: `integer`):

Total parallel checks. At most 2 requests per host are ever in flight, whatever this value is.

## `maxCrawlDelaySecs` (type: `integer`):

A Crawl-delay in robots.txt is respected between request starts per host, capped at this value so a huge delay cannot stall the run. 0 disables crawl-delay handling.

## `timeoutSecs` (type: `integer`):

Timeout per HTTP request.

## Actor input object example

```json
{
  "urls": [
    "https://ghost.org",
    "https://www.python.org"
  ],
  "checkUrls": true,
  "maxUrls": 50,
  "includeExternalHosts": false,
  "useGetFallback": true,
  "maxConcurrency": 10,
  "maxCrawlDelaySecs": 10,
  "timeoutSecs": 20
}
```

# Actor output Schema

## `results_overview` (type: `string`):

No description

## `summary` (type: `string`):

No description

# 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://ghost.org",
        "https://www.python.org"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("codesidian/sitemap-url-health-checker").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://ghost.org",
        "https://www.python.org",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("codesidian/sitemap-url-health-checker").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).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://ghost.org",
    "https://www.python.org"
  ]
}' |
apify call codesidian/sitemap-url-health-checker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,codesidian/sitemap-url-health-checker"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/4unwHeWIzDz6nkMgG/builds/Qjb4IDaEfpN6olnu5/openapi.json
