Repository navigation
feat(core): docusaurus serve uses 301 for its canonical URL redirects (AI-assisted) - #12907
Merged
Merged
Conversation
…ts (AI-assisted) The trailing slash, clean URL and merged slashes redirects that Docusaurus does for sites with a baseUrl now use 301, like serve-handler does for the same redirects without a baseUrl, and like GitHub Pages and Netlify. The redirect of requests outside the baseUrl stays 302: it only exists in docusaurus serve. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Size Change: 0 B Total Size: 12.1 MB ℹ️ View Unchanged
|
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Size Change: 0 B Total Size: 12.1 MB ℹ️ View Unchanged
|
⚡️ Lighthouse report for the deploy preview of this PR
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
docusaurus serveused two status codes for the same redirects, depending on the site'sbaseUrl:baseUrl, serve-handler does the trailing slash, clean URL (.html,/index) and repeated slashes (//) redirects, with a 301.baseUrl, Docusaurus does them itself, because serve-handler drops thebaseUrlfrom its redirects (Problems with locale url on homepage and blog #10078, fix(core):docusaurus serveredirects should include the site/baseUrl/prefix #10090). They used a 302.This PR makes the Docusaurus redirects to canonical URLs permanent (301), like serve-handler and most static hosts. The redirect of requests outside the
baseUrl(/→/base/) stays 302.baseUrl(serve-handler)baseUrl(Docusaurus)baseUrl, to thebaseUrl(Docusaurus)Why 301 for canonical URL redirects
src/index.js#L121-L123), and itsredirects[].typeoption only applies to custom redirect rules. A site now gets the same status code with or without abaseUrl, and we don't need to override serve-handler.docusaurus servesends HTTP caching headers (AI-assisted) #12903. Everydocusaurus serveresponse, redirects included, now hasCache-Control: no-cache, so browsers check a 301 with the server again before following it. Without it, Chromium caches a 301 forever, and switchingtrailingSlashon the same port gaveERR_TOO_MANY_REDIRECTSuntil the user cleared the browser cache: that was the good reason to use 302.GETandHEAD, the only methods a static server serves. 308 (Cloudflare Pages, Vercel) also keeps the method ofPOSTrequests, which a static site never handles. 301 keeps Docusaurus consistent with serve-handler, GitHub Pages and Netlify.Why the redirect to the
baseUrlstays 302baseUrlbelong to another site, or don't exist. This redirect is adocusaurus serveconvenience (fix(v2): respect baseUrl in serving command #4924), so its target is not a permanent location: it depends on the config of the site thatdocusaurus servecurrently serves on this port.vite previewredirects/to itsbasewith a 302.How popular hosts behave
Measured with curl on 2026-11-06, on the deployments of slorber/trailing-slash-guide, which has the same
file/folder/bothlayout as our test fixture. Vercel's guide deployments now return 402, so its row comes from its docs and from live sites (nextjs.org, vercel.com)..htmland/index//Cache-Controlof the redirectmax-age=600trailingSlash,cleanUrls)public, max-age=0, must-revalidateNo host uses 302 for these redirects. Hosts disagree between 301 and 308, which behave the same in browsers for static sites.
Other local servers
serve(vercel/serve, uses serve-handler)//http.serverhttp-servervite preview/and/index.htmltobasenext starttrailingSlashastro preview(static)Test Plan
baseUrl.pnpm test, ESLint andtypecheck:testspass.Test links
Deploy preview: https://deploy-preview-12907--docusaurus-2.netlify.app/
No documentation change: the docs don't mention the status codes of
docusaurus serveredirects.Related issues/PRs
docusaurus servesends HTTP caching headers (AI-assisted) #12903:Cache-Control: no-cacheon every response, which makes permanent redirects safe.docusaurus serveredirects should include the site/baseUrl/prefix #10090 and Problems with locale url on homepage and blog #10078: why Docusaurus does these redirects itself with abaseUrl.baseUrl.(AI-assisted)
🤖 Generated with Claude Code