Serving under a path
Your docs can live at a path of your product’s domain - example.com/docs - instead of a domain of their own. Your site keeps serving everything else, and a proxy in front of it passes /docs and everything under it to the docs site.
On the WriteDocs platform, the WriteDocs team sets up the address under a path for your project - ask us. The site is then built with that path as its basePath, and every address the docs make starts with it.
basePath
{
"domain": "example.com",
"basePath": "/docs"
}The path the site is served under, like /docs or /help/docs. It starts with / and has no / at the end; each part has lowercase letters, digits, - and _ only. Leave it out (or set "" or "/") for a site at the root of its domain - the default. Any other value is an error in writedocs validate and in the editor.
Full URLs - canonical links, sitemap.xml, llms.txt, link previews - are domain + basePath, like https://example.com/docs/guides/setup/. domain is the domain your readers see (example.com), not the site’s WriteDocs address behind the proxy.
The platform writes both into the build when your writedocs.json doesn’t have them, so you don’t need to. A domain or basePath you write yourself takes precedence: leave them out, or keep them the same as the address the WriteDocs team set up.
What changes
With "basePath": "/docs", every address the site makes starts with /docs:
- the links in the sidebar, tabs, version and language switchers, dropdowns, breadcrumbs, the footer, the topbar and the page menu;
- the site’s own files - styles, scripts, fonts, icons, the logo and favicon, link preview images;
- search;
sitemap.xml,robots.txt,llms.txt,llms-full.txtand each page’s Markdown copy;- the MCP server, at
/docs/mcp; - redirects, and the redirects from
/docsand from folder addresses to the first page.
writedocs dev serves the preview under the path too: it opens at http://localhost:4321/docs/.
Your pages keep site addresses
In your pages and in writedocs.json, keep writing addresses from the site’s root, without /docs. The base is added for you:
| You write | Readers get |
|---|---|
[Setup](/guides/setup) | /docs/guides/setup |
 | /docs/images/flow.png |
<a href="/api/">, <img src="/logo.svg"> | /docs/api/, /docs/logo.svg |
<Card href="/guides/setup"> | /docs/guides/setup |
"favicon": "/images/favicon.svg" | /docs/images/favicon.svg |
{ "source": "/old", "destination": "/new/" } in redirects | /docs/old → /docs/new/ |
../setup, https://example.com/pricing, #install | unchanged |
A link written with the base already in it - /docs/guides/setup - gets it twice and leads nowhere. writedocs broken-links reports it.
The same pages build with or without basePath, so you can move the docs between docs.example.com and example.com/docs without editing them.
Behind your proxy
The site stays at its WriteDocs address - say acme.writedocs.io - and your main site passes /docs and everything under it on to that address, with the path unchanged: a request for example.com/docs/guides/setup/ asks for acme.writedocs.io/docs/guides/setup/. Everything outside /docs stays yours. In the examples, replace acme.writedocs.io with your project’s address and /docs with your path.
const DOCS_HOST = 'acme.writedocs.io';
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === '/docs' || url.pathname.startsWith('/docs/')) {
url.hostname = DOCS_HOST;
return fetch(new Request(url, request));
}
return fetch(request); // the rest of your site
},
};Route the Worker to example.com/docs*, or to the whole domain if it also serves the rest of your site.
{
"rewrites": [
{ "source": "/docs", "destination": "https://acme.writedocs.io/docs" },
{ "source": "/docs/:path*", "destination": "https://acme.writedocs.io/docs/:path*" }
]
}module.exports = {
async rewrites() {
return [
{ source: '/docs', destination: 'https://acme.writedocs.io/docs' },
{ source: '/docs/:path*', destination: 'https://acme.writedocs.io/docs/:path*' },
];
},
};location /docs {
proxy_pass https://acme.writedocs.io; # no path after the host: the path goes as it came
proxy_set_header Host acme.writedocs.io;
proxy_ssl_server_name on;
}- Keep the path. A proxy that strips
/docsbefore passing the request on breaks every page: the site’s files are under/docs/at its WriteDocs address too. - Send the site’s WriteDocs address as the host. The request that reaches WriteDocs should carry
acme.writedocs.ioin theHostheader, not your domain - the Cloudflare, Vercel and Next.js examples do this by themselves; in Nginx it’s theproxy_set_header Hostline. - Redirects pass through. The site’s redirects answer with addresses under
/docs, so the reader stays on your domain. - “Not found” pages come from the docs site, with the status 404 and the site’s own look. An address outside
/docsis never sent to the docs.
Limits
-
robots.txtand the sitemap. Search engines only readrobots.txtat the root of your domain -example.com/robots.txt, which is yours, not the docs’. The docs’ own copy at/docs/robots.txthas the rules and theSitemap:line to copy into yours:example.com/robots.txtUser-agent: * Allow: /docs/ Sitemap: https://example.com/docs/sitemap.xmlOr submit
https://example.com/docs/sitemap.xmlin your search engine’s webmaster tools (Google Search Console, Bing Webmaster Tools). -
Your own CSS and JavaScript files are used as written. An address inside a
.cssor.jsfile of your project, or in thecontentof ascriptsentry, doesn’t get the base: write it in full (url(/docs/images/bg.png)), or, in a file inpublic/, relative to the file. The same goes for a_redirectsfile of your own: its rules match full paths, so they start with/docs. -
Addresses computed in code aren’t changed. An attribute written as an expression -
<a href={link}>- and anything a React snippet renders are left as they are; include the base yourself there. -
One path at a time. The site is built for one path, so it isn’t also served at the root of a domain.