A deployment gate for sitemap response mismatches

A sitemap should list the canonical URLs you intend search engines to crawl. That makes a release-time response check useful: it can catch a sitemap entry that now redirects, returns an error, or sends an indexing-blocking HTTP header.

The implementation takes an array of URLs plus an injected fetch function. Dependency injection is intentional: the validator only needs a response-like object, so its behavior can be checked with controlled fixtures instead of coupling tests to a particular HTTP transport.

The key request decision is disabling automatic redirect following. If the client follows a 301 or 302, the final destination may return 200 and hide the fact that the sitemap named an outdated URL. With manual redirect handling, any 3xx response becomes an explicit redirect problem. Responses outside the 2xx range are reported as status-specific problems, while successful responses remain eligible for the header check.

For each URL, return the URL, status, raw X-Robots-Tag value, a list of problems, and an ok boolean. Parse the header case-insensitively and treat both noindex and none as failures. A result can therefore distinguish a routing issue from a noindex-header issue, which gives the release owner a clearer place to fix it: sitemap generation, routing, infrastructure headers, or application output.

Keep HTML robots meta validation separate. A header is available from the response metadata, but a meta directive requires fetching and parsing the HTML document. A page can return 200 with no blocking header and still contain a robots meta tag, so that should be a second check with its own parsing boundary.

This gate reports what the server returns at check time. It does not validate the sitemap XML, account for robots.txt, reproduce crawler behavior, or establish that a search engine has crawled, indexed, or removed a URL. Its value is narrower: prevent known sitemap URLs from shipping with an immediately visible redirect, error status, or blocking response header.

Working example

/** * Checks the response currently served for each sitemap URL. This is a deployment * check only: it cannot determine whether Google has crawled or indexed a URL. * HTML robots meta tags require fetching and parsing the HTML separately. */ export async function checkSitemapUrls(urls, fetchFn) { if (!Array.isArray(urls)) throw new TypeError('urls must be an array'); if (typeof fetchFn !== 'function') throw new TypeError('fetchFn must be a function'); return Promise.all(urls.map(async (url) => { const response = await fetchFn(url, { redirect: 'manual' }); const xRobotsTag = response.headers?.get?.('x-robots-tag') ?? ''; const directives = xRobotsTag.toLowerCase().split(/[\s,]+/); const problems = []; if (response.status >= 300 && response.status < 400) { problems.push('redirect'); } else if (response.status < 200 || response.status >= 300) { problems.push(`http-${response.status}`); } if (directives.includes('noindex') || directives.includes('none')) { problems.push('noindex-header'); } return { url, status: response.status, xRobotsTag, problems, ok: problems.length === 0, }; })); } 

Read the full article: https://chriseugenerodriguez.com/blog/check-sitemap-urls-for-redirects-and-noindex