Menu

Hreflang return links: audit them with a short Python script and no dependencies
📰

Hreflang return links: audit them with a short Python script and no dependencies

DEV Community: python·Hanin Mp·about 18 hours ago
#Vau2V4qj
#devtopython#devto#dev#code#default
Reading 0:00
15s threshold

Hreflang fails quietly. When two language pages do not point at each other, Google does not show an error in your browser or in the page. The annotation simply does not do its job, and the first sign is the wrong language version ranking in the wrong country.

This tutorial builds a small checker that fetches one page, follows the alternates it lists, and reports missing return links, missing self-references, malformed codes and relative URLs. It uses only the Python standard library.

What the rules actually say

Everything below comes from Google's page on localized versions. I read it in full before writing the code.

Every version must list itself and all other versions, including the default page.

Alternate URLs must be fully qualified, with the protocol. A root-relative path like /de/ is not enough.

Links must be reciprocal.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.