-
I have a single nextjs app serving multiple domains. I have the actual sitemap files in the public dir, like public/sitemapCOM.xml, public/sitemapDE.xml etc I've tried to do this by adding the following to express in server.js server.get("/sitemap.xml", (req, res) => { I end up with getting a missing page (404) Is there any other way of accomplishing this? Any help would be greatly appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you're using API routes then Express.js stuff won't work. If your site is hosted on Vercel, you could look into adding Rewrites in your now.json file, maybe that would help ? |
Beta Was this translation helpful? Give feedback.
-
You could build the sitemap at export async function getServerSideProps({ req, res }) {
const sitemapCom = createSitemap();
const sitemapDe = createSitemap();
const sitemap = domain === 'COM' ? sitemapCom : sitemapDe;
res.setHeader('Content-Type', 'text/xml');
res.write(sitemap);
res.end();
return {
props: {},
}
} |
Beta Was this translation helpful? Give feedback.
You could build the sitemap at
sitemap.xml.js
and usegetServerSideProps
.