[SEO] - How to use sitemap and robots with next-intl #888
-
Hi ! I'm watching this video for SEO in Next.js 14 and i wonder how to use sitemap (43:30 in the video) and robots (50:40) with next-intl. The sitemap.xml and the robots.txt have to be in the [locale] folder ? How to set sitemap.xml and robots.txt proprely with the dynamic "[locale]" folder ? do you have any example ? Thank you so much ! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Next.js is currently missing support for What would you need you need from This being said, it would be cool to have a guide for this at some point. If someone has a working implementation, it would be cool if you could share it here. |
Beta Was this translation helpful? Give feedback.
-
@davidbourrel I'm using headers to get local information for robots.txt as it's in my root. Both are coming from a CMS's restapi:
My sitemap.xml is within [locale] and I use this code:
|
Beta Was this translation helpful? Give feedback.
-
To implement a sitemap.xml and robots.txt with dynamic localization (e.g., using [locale] in Next.js), you can follow these steps: Sitemap.xml: Create a function to generate your sitemap dynamically based on the localized pages of your Next.js application. This function will generate the sitemap.xml content. const generateSitemap = async () => { const sitemap = return sitemap; export default generateSitemap; Create an API route that will serve the dynamically generated sitemap. export default async function handler(req, res) { Once you've implemented the sitemap, submit it to search engines like Google Search Console. Similarly, create a function to generate your robots.txt dynamically based on your localized pages. const generateRobotsTxt = async () => { const robotsTxt = return robotsTxt; export default generateRobotsTxt; Create an API route to serve the dynamically generated robots.txt. export default async function handler(req, res) { Make sure to include the generated robots.txt and sitemap.xml URLs in your Next.js app where appropriate, such as linking them in the header. Certainly! For SEO, you may want to include meta tags in the head of your pages to provide additional information for search engines. Here's how you can add two common meta tags, title and description, to the head of your pages: Modify the Head of Your Pages: jsx const Layout = ({ children }) => { <title>Your Site Title</title> {/* Add any other SEO-related meta tags as needed */} {children} ); }; export default Layout; Include Layout in Your Pages: jsx function MyApp({ Component, pageProps }) { export default MyApp; Additional Notes: Locale-Specific SEO: Remember to adapt these examples to fit the specifics of your project. SEO best practices may vary, so consider other meta tags or elements that might be relevant to your content and audience. |
Beta Was this translation helpful? Give feedback.
@davidbourrel I'm using headers to get local information for robots.txt as it's in my root. Both are coming from a CMS's restapi: