What is a sitemap, and what does it not do?
How does the built-in sitemap.ts work?
Ts
How do I split a large sitemap with generateSitemaps?
Ts
What does the next-sitemap package do differently?
Bash
Json
Js
How do I choose between them?
Ts
How do I migrate from next-sitemap to sitemap.ts?
- Add app/sitemap.ts and app/robots.ts and run the site locally. Open /sitemap.xml and /robots.txt and compare the URL list with your old generated file.
- Remove the postbuild script, delete next-sitemap.config.js and uninstall the package.
- Delete the old generated files from public, such as sitemap.xml, sitemap-0.xml and robots.txt. A leftover file at the same path as a route is a source of confusion, so do not leave it there. If these files were committed, remove them from git as well.
- Move your exclude rules into code (a filter on the URL list) and your robotsTxtOptions policies into the rules array of robots.ts.
- Deploy, request /sitemap.xml with curl, and submit it again in Search Console. If your old setup used an index with numbered files, remove the old sitemap-0.xml entries from the report, because those URLs will no longer exist.
What sitemap mistakes should I avoid?
- Relative URLs or the wrong host. Every entry must be a full URL on the host and protocol you want indexed. A staging domain or http:// left in an environment variable is the usual cause.
- Listing URLs that redirect, return an error or carry noindex. A sitemap should contain only the final, indexable, 200 URLs.
- Trailing-slash mismatches. If your pages live at /about and the sitemap says /about/, you are listing a URL that redirects.
- Canonicals that disagree. The canonical tag on the page should match the sitemap entry. If they differ, Google may follow the canonical and ignore the listing.
- A stale or fake lastmod. Setting every entry to the build time teaches crawlers to ignore the field. Use the real last content change, or leave it out.
- Listing paginated, filtered or sorted duplicates, such as ?sort=price pages. List the clean category URL once.
- Putting a Disallow rule on a URL you also want to be removed with noindex. Google cannot read a noindex tag on a page it is not allowed to fetch.
How do I check that the sitemap works?
Bash