sitemap question (languages)
Answered
Ruwbix posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
This is my current sitemap. I have my default route which basically auto redirects to the language. Is this the correct way of doing things (never set up a sitemap before)? or am i supposed to define the languages as well? Also, the content is static, that means i shouldn't define a lastModified, should I?
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://immotogo.be/nl</loc>
</url>
<url>
<loc>https://immotogo.be/fr</loc>
</url>
<url>
<loc>https://immotogo.be/en</loc>
</url>
<url>
<loc>https://immotogo.be/nl/destination/gern</loc>
</url>
<url>
<loc>https://immotogo.be/fr/destination/gern</loc>
</url>
<url>
<loc>https://immotogo.be/en/destination/gern</loc>
</url>
<url>
<loc>https://immotogo.be/nl/destination/la-douane</loc>
</url>
<url>
<loc>https://immotogo.be/fr/destination/la-douane</loc>
</url>
<url>
<loc>https://immotogo.be/en/destination/la-douane</loc>
</url>
</urlset>
Answered by fuma 💙 joulev
Alright I've just read the whole docs again
You can either generate one via Route Handler, with an XML generator (find a library), or manually write a
If you directly list urls without locale (for example,
You can either generate one via Route Handler, with an XML generator (find a library), or manually write a
sitemap.xml
If you directly list urls without locale (for example,
/my-blog/name
), ensure that each page has alternate tags (alternates.languages
and alternates.canoncal
) so that Google know all variants of your page. In this case, you can directly use the built-in Sitemap Route API28 Replies
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
should i define somewhere that my base url redirects to the language?
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
You should add a
https://developers.google.com/search/docs/specialty/international/localized-versions#sitemap
xhtml:link
element with hreflang
attribute according to their docs: https://developers.google.com/search/docs/specialty/international/localized-versions#sitemap
it's similar to the alternate meta tag
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
I don't think nextjs
MetadataRoute.Sitemap
has a built-in feature for that, does it?import { siteConfig } from '@/config/site';
import { i18n } from '@/i18n-config';
import { MetadataRoute } from 'next';
export default function sitemap(): MetadataRoute.Sitemap {
const BASE_URL = siteConfig.url || 'https://immotogo.be';
const defaultRoutes: MetadataRoute.Sitemap = i18n.locales.map((locale) => ({
url: `${BASE_URL}/${locale}`,
}));
const gernRoutes: MetadataRoute.Sitemap = i18n.locales.map((locale) => ({
url: `${BASE_URL}/${locale}/destination/gern`,
}));
const laDouaneRoutes: MetadataRoute.Sitemap = i18n.locales.map((locale) => ({
url: `${BASE_URL}/${locale}/destination/la-douane`,
}));
return [...defaultRoutes, ...gernRoutes, ...laDouaneRoutes];
}
probably easier to just manually make a
sitemap.xml
in this case?or does it auto do that when I set it up in
metadata
?![Image](https://cdn.discordapp.com/attachments/1160876490943102977/1160880745477308486/image.png?ex=65364571&is=6523d071&hm=b04fe2a76705e65ef154d90bde14fbd1ee36d17d10ce14014c892f0ce9c48d7f&)
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
Google docs didn't describe that, defining alternates in page level might be supported.
Assume you're using https://github.com/iamvishnusankar/next-sitemap, I think it can be implemented with the
Assume you're using https://github.com/iamvishnusankar/next-sitemap, I think it can be implemented with the
alternateRefs
option![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
i think they are using: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generate-a-sitemap (based on the imports in codeblock)
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
I haven't checked this new API before, surely it doesn't support
langhref
attribute for now![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
doesn't look like it
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
and perhaps Next.js won't be that smart, since sitemap is at the root directory of your website, it isn't able to get
metadata
from url and generate alternates for you![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
i think you can actually put a sitemap in a non-root path, at least some canarys ago you could (so as it isn't mentioned in docs, i wouldn't trust that much)
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
that's by Google's docs
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
ohhhhhh i was meaning the nextjs docs where it mentioned only root sitemap.ts was used
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
Google only look for
xxx.com/sitemap.xml
, subdirectories are not considered![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
yeah, i think you may have success importing them through the sitemap or robots.. but i don't know that much SEO (so best to just use root imo)
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
Alright I've just read the whole docs again
You can either generate one via Route Handler, with an XML generator (find a library), or manually write a
If you directly list urls without locale (for example,
You can either generate one via Route Handler, with an XML generator (find a library), or manually write a
sitemap.xml
If you directly list urls without locale (for example,
/my-blog/name
), ensure that each page has alternate tags (alternates.languages
and alternates.canoncal
) so that Google know all variants of your page. In this case, you can directly use the built-in Sitemap Route APIAnswer
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
so like this
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://immotogo.be/</loc>
<xhtml:link rel="alternate" hreflang="nl" href="https://immotogo.be/nl"/>
<xhtml:link rel="alternate" hreflang="fr" href="https://immotogo.be/fr"/>
<xhtml:link rel="alternate" hreflang="en" href="https://immotogo.be/en"/>
</url>
<url>
<loc>https://immotogo.be/destination/gern</loc>
<xhtml:link rel="alternate" hreflang="nl" href="https://immotogo.be/nl/destination/gern"/>
<xhtml:link rel="alternate" hreflang="fr" href="https://immotogo.be/fr/destination/gern"/>
<xhtml:link rel="alternate" hreflang="en" href="https://immotogo.be/en/destination/gern"/>
</url>
<url>
<loc>https://immotogo.be/destination/la-douane</loc>
<xhtml:link rel="alternate" hreflang="nl" href="https://immotogo.be/nl/destination/la-douane"/>
<xhtml:link rel="alternate" hreflang="en" href="https://immotogo.be/en/destination/la-douane"/>
<xhtml:link rel="alternate" hreflang="fr" href="https://immotogo.be/fr/destination/la-douane"/>
</url>
</urlset>
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
it looks good
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
doesn't seem to like the <xhtml:link />
![Image](https://cdn.discordapp.com/attachments/1160876490943102977/1160907525047193733/image.png?ex=65365e62&is=6523e962&hm=4e517ed2871363322451d0f1727554398196e4402ed57ce28309432621464ad7&)
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
xmlns:xhtml="http://www.w3.org/1999/xhtml"
at urlset
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
alright, it doesn't return it in a formatted list anymore. That an issue?
![Image](https://cdn.discordapp.com/attachments/1160876490943102977/1160908536298098718/image.png?ex=65365f53&is=6523ea53&hm=7aa8e5eae80aa802628f64dddb4d115ba042869f6a8599e84e5bc39fe1fe62b9&)
![Image](https://cdn.discordapp.com/attachments/1160876490943102977/1160908536650416188/image.png?ex=65365f53&is=6523ea53&hm=4709d8f864cee455a7440d5e540d85e95e32536d405e83e9e792b2a86284808d&)
looks fine in source code though, just doesn't seem to like those xhtml:link element. is there like tools to check if my sitemap is valid?
![Avatar](https://cdn.discordapp.com/avatars/572329183334891520/3ea2e2e134a2327e2b8a7738876a17b5.webp?size=256)
fuma 💙 joulev
it's fine
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
i have it rendering weird often
![Avatar](https://cdn.discordapp.com/avatars/166144585544892417/0a4a916f6aa5d84a7e5342fd5fb1281c.webp?size=256)
RuwbixOP
alright awesome. Thanks a lot guys