Skip to content

Commit d7d2e26

Browse files
committed
fix: use trailing slashes in canonical URLs and sitemap
Cloudflare Pages 308-redirects to trailing slashes. Canonical URLs and sitemap entries must match the final URL to avoid soft 404s. Also simplify robots.txt since Cloudflare prepends its own rules.
1 parent 731c349 commit d7d2e26

2 files changed

Lines changed: 5 additions & 30 deletions

File tree

apps/web/public/robots.txt

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1 @@
1-
User-agent: *
2-
Allow: /
3-
41
Sitemap: https://ooxml.dev/sitemap.xml
5-
6-
# Block AI training crawlers
7-
User-agent: GPTBot
8-
Disallow: /
9-
10-
User-agent: CCBot
11-
Disallow: /
12-
13-
User-agent: Google-Extended
14-
Disallow: /
15-
16-
User-agent: Bytespider
17-
Disallow: /
18-
19-
User-agent: ClaudeBot
20-
Disallow: /
21-
22-
User-agent: Amazonbot
23-
Disallow: /
24-
25-
User-agent: Applebot-Extended
26-
Disallow: /
27-
28-
User-agent: meta-externalagent
29-
Disallow: /

apps/web/scripts/prerender.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ function specPageHtml(): string {
112112

113113
function buildHead(path: string): string {
114114
const seo = getSeoMeta(path);
115-
const url = `${SITE_URL}${path}`;
115+
// Cloudflare Pages adds trailing slashes via 308 redirect, so canonical must match
116+
const canonicalPath = path === "/" ? path : `${path}/`;
117+
const url = `${SITE_URL}${canonicalPath}`;
116118

117119
const meta = [
118120
`<title>${escapeHtml(seo.title)}</title>`,
@@ -207,8 +209,9 @@ function generateSitemap(paths: string[]): string {
207209
const urls = paths.map((path) => {
208210
const priority = path === "/" ? "1.0" : path.startsWith("/docs/") ? "0.8" : "0.7";
209211
const changefreq = path === "/" ? "weekly" : "monthly";
212+
const loc = path === "/" ? SITE_URL + path : `${SITE_URL}${path}/`;
210213
return ` <url>
211-
<loc>${SITE_URL}${path}</loc>
214+
<loc>${loc}</loc>
212215
<changefreq>${changefreq}</changefreq>
213216
<priority>${priority}</priority>
214217
</url>`;

0 commit comments

Comments
 (0)