Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(sitemap): add .html extension to URLs when build.format is file
When `build.format` is set to `'file'`, output files have .html
extensions (e.g., about.html) but the sitemap was generating URLs
without extensions (e.g., /about instead of /about.html), resulting
in 404s when crawlers follow those links.

Fixes #15526
  • Loading branch information
mixelburg committed Feb 19, 2026
commit 1c0a50b17214f926949aeb8d70a75cda65978033
5 changes: 5 additions & 0 deletions .changeset/sitemap-file-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/sitemap': patch
---

Fix sitemap URLs missing `.html` extension when `build.format` is set to `file`
6 changes: 5 additions & 1 deletion packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {

const newUrl = new URL(fullPath, finalSiteUrl).href;

if (config.trailingSlash === 'never') {
if (config.build.format === 'file' && !newUrl.endsWith('/')) {
// When build.format is 'file', output files have .html extension
// (e.g., /about → /about.html), so sitemap URLs should match
urls.push(newUrl + '.html');
} else if (config.trailingSlash === 'never') {
urls.push(newUrl);
} else if (config.build.format === 'directory' && !newUrl.endsWith('/')) {
urls.push(newUrl + '/');
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/sitemap/test/trailing-slash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ describe('Trailing slash', () => {
await fixture.build();
});

it('URLs do not end with trailing slash', async () => {
it('URLs have .html extension', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;

assert.equal(urls[0].loc[0], 'http://example.com');
assert.equal(urls[1].loc[0], 'http://example.com/one');
assert.equal(urls[2].loc[0], 'http://example.com/two');
assert.equal(urls[1].loc[0], 'http://example.com/one.html');
assert.equal(urls[2].loc[0], 'http://example.com/two.html');
});
});
});
Expand Down
Loading