Robots.txt, XML sitemaps, canonicals and hreflang often appear in the same SEO audit, but they are not interchangeable. Each answers a different question about URL discovery and interpretation.
Short answer: Robots.txt controls where a bot may crawl. A sitemap suggests canonical URLs for discovery. A canonical identifies the preferred version of identical or very similar content. Hreflang connects equivalent language or regional versions.
Robots.txt: access, not removal from the index
The file sits at the host root and contains rule groups for user agents. A Disallow prevents crawling of the matching path, but it is not a dependable way to remove an already known URL from results. Index control uses noindex on a page the crawler can access or an appropriate HTTP header.
A public marketing website will often need a simple, intentional policy and an absolute sitemap declaration:
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xml
Actual rules depend on the website. Admin paths, internal search results or parameter traps may need a different treatment.
Sitemap: a proposed list of canonical URLs
A sitemap should contain absolute production URLs that return 200, permit indexing and identify themselves as canonical. It should exclude redirects, error routes, staging hosts and pages with noindex.
Submitting a sitemap supports discovery and reporting in Search Console, but remains a hint. It does not compel a search engine to crawl or index every URL.
Canonical: choosing between duplicate versions
rel="canonical" in the head identifies the version the publisher considers representative. Google treats redirects and canonical annotations as strong signals, with sitemap inclusion as a weaker signal. Agreement reduces ambiguity.
Consider a conflict: a parameter URL points its canonical to the base page, while every internal link and the sitemap point to the parameter. The system receives contradictory guidance and may select a different canonical.
Hreflang: language matching, not duplication
A Greek and English page can be equivalent translations without being duplicate versions for canonical consolidation. Each is normally self-canonical and identifies both languages:
<link rel="alternate" hreflang="el" href="https://example.com/ypiresia" />
<link rel="alternate" hreflang="en" href="https://example.com/en/service" />
<link rel="alternate" hreflang="x-default" href="https://example.com/ypiresia" />
Annotations need return links. If Greek points to English but English does not point back, the relationship may be ignored.
One URL, one consistent story
For each indexable route, signals should tell the same story:
- robots rules do not block it,
- a crawlable link leads to it,
- it returns
200, - it carries no
noindex, - it is self-canonical,
- it appears in the sitemap,
- it has reciprocal hreflang where a translation exists.
For a page that should not be indexed, remove it from the sitemap and indexable internal paths. Choose noindex, authentication or real access control according to the reason. Never rely on robots.txt to protect private information.
Verify after deployment
Build output can be correct while the live website fails. Request the exact production URLs and inspect status, content type and body. An SPA fallback can return home-page HTML with status 200 at /robots.txt or a sitemap path, creating a soft failure.
Repeat these checks after changes to the domain, redirects, routing, localisation, CMS or CDN. Technical SEO becomes more dependable when these tests are automated.