Nextjs 14 why my dynamic sitemap.xml not working?
Unanswered
Thrianta posted this in #help-forum
ThriantaOP
According to nextjs docs I crate an sitemap.js file inside my app directory for crate an dynamic sitemap but when I go http://localhost:3000/sitemap.xml I see 404 not found
enter image description here
here my code
app
sitemap.js
but when I crate an sitemap.xml inside my app directory I can see only static content not getting any content from sitemap.js
enter image description here
here my code
app
sitemap.js
export default function sitemap() {
return [
{
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: 'https://acme.com/about',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
},
{
url: 'https://acme.com/blog',
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.5,
},
]
}but when I crate an sitemap.xml inside my app directory I can see only static content not getting any content from sitemap.js
3 Replies
@Thrianta According to nextjs docs I crate an sitemap.js file inside my app directory for crate an dynamic sitemap but when I go http://localhost:3000/sitemap.xml I see 404 not found
enter image description here
here my code
app
sitemap.js
export default function sitemap() {
return [
{
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: 'https://acme.com/about',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
},
{
url: 'https://acme.com/blog',
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.5,
},
]
}
but when I crate an sitemap.xml inside my app directory I can see only static content not getting any content from sitemap.js
an old workaround is using route handlers and manually returning the xml, but are you on latest next.js version? (i haven't seen this bug yet, but also not on latest rn)
@riský an old workaround is using route handlers and manually returning the xml, but are you on latest next.js version? (i haven't seen this bug yet, but also not on latest rn)
ThriantaOP
Finally, I found out that there was no issue with my code. For localhost, the correct URL path for the sitemap will be http://localhost:3000/sitemap.xml/0.1. However, when working on production, it will be http://domainname/sitemap.xml.
O.O that sounds like a bug...