Back to News & Insights
SEO September 24, 2026 · 4 min read

Find Sitemap URLs with Conflicting Canonicals

A sitemap lists /guides/, but the page declares /resources/guides/ as its canonical URL. Which...

Find Sitemap URLs with Conflicting Canonicals

A sitemap lists /guides/, but the page declares /resources/guides/ as its canonical URL. Which address should your publishing pipeline keep? Audit the sitemap entry, the final URL after redirects, and the HTML canonical separately. Report the disagreement; then a human decides which URL represents the page.

Google recommends putting the URLs you want shown as canonical in a sitemap and avoiding contradictory canonical signals. A sitemap entry and an HTML rel="canonical" are signals, though: the checker below finds inconsistent declarations. It cannot declare which URL Google will choose. See Google's sitemap guidance and canonical methods.

AI disclosure: This article was drafted with AI. The author must verify its technical claims and code before publication and select the truthful DEV editor disclosure tier.

| Value | What it tells us | | --- | --- | | Sitemap URL | The URL the publisher submitted as a canonical candidate. | | Final response URL | The URL reached after ordinary HTTP redirects. | | HTML canonical | The URL named by a in the returned HTML. |

For example, if a sitemap includes https://example.test/a and the fetched HTML points to https://example.test/b, the script prints CONFLICT. If /a redirects to /b, it also prints REDIRECTED. Neither output is proof of a search penalty; both indicate a place to examine your routing and page-generation rules.

Save the following as auditcanonicals.py. Pass it a trusted local sitemap XML file, not a remote URL. It checks at most 200 entries, uses an eight-second request timeout, and reads only the first 512 KB of each HTML response. Run it only against a site you are authorized to inspect. Python 3.12 needs no third-party package.

Run python3 auditcanonicals.py sitemap.xml. A sitemap entry with an explicit matching HTML canonical prints OK. A missing HTML canonical prints REVIEWNOHTMLCANONICAL, which is a review item, not an automatic error. A redirect and mismatch can appear together.

For a small local check, I ran the script against a temporary HTTP server with these fixtures:

| Fixture path | Returned page behavior | Observed classification | | --- | --- | --- | | /ok | Canonical points to /ok. | OK | | /wrong | Canonical points to /other. | CONFLICT | | /missing | No HTML canonical tag. | REVIEWNOHTMLCANONICAL | | /redirect | Redirects to /ok; sitemap still lists /redirect. | REDIRECTED|CONFLICT | | /multiple | Two different HTML canonicals. | REVIEWMULTIPLECANONICALS |

The five outputs matched the expected classifications under Python 3.12. This is a test of the script's branch behavior, not proof that a real crawler interprets every live site in the same way. Recreate equivalent fixtures for your site's redirect and template rules before running a larger audit.

The comparison removes URL fragments and lowercases the scheme and host. It deliberately preserves paths and query strings: changing either can identify a different resource. Review harmless URL normalization differences rather than rewriting them blindly.

Take one CONFLICT row and answer four questions: Did the submitted URL redirect? Is the HTML canonical absolute or relative? Is the destination page actually the preferred version? Does the sitemap generator use the same URL rule as the page renderer? Fix the responsible generator or redirect rule, then rerun the audit.

This small script reads one uncompressed URL sitemap, follows normal redirects, and scans the fetched HTML only. It does not parse sitemap indexes, render JavaScript, inspect Link HTTP headers, enforce robots.txt, or tell you what Google selected. It also uses a simplified UTF-8 decode; adapt it for a site's declared charset. Large sites should add rate limiting, host allowlisting, index traversal, and respectful scheduling before running a broader audit.

The useful output is a review queue with reasons, not a green SEO score. A person can inspect the URL pair, correct conflicting publication signals, and verify the intended result with the appropriate search tools.

Want to discuss this further?

Book a free strategy call with our team to see how these insights apply to your specific business goals.

Book a consultation