question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to dynamic set sitemap in robots.txt

See original GitHub issue

in front-end, I can get window.location.origin like this screenshot 截圖 2021-03-31 上午11 10 31

but i want set dynamic sitemap in nuxt.config.js in robots.txt ex: robots: { UserAgent: '*', Sitemap: ${window.location.origin}/sitemap.xml }, here window object is not exist , Is there any good way to resolve it ? Thanks !

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
TitanFightercommented, Aug 25, 2021
modules: [
    ...
    ['@nuxtjs/robots', {
      UserAgent: '*',
      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`
    }],
    ...
]
0reactions
IsraelOrtunocommented, Oct 31, 2022

Not sure about the hook but robots.txt serves for more purposes than adding the sitemap URL (which will likely be generated by your own app or a third party module). The point here is that if you pretend to have a dynamic sitemap URL (or any other property in your robots file), it has to run on SSR as that function needs to be executed, otherwise you can make it static with an ENV var.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create dynamic sitemap, humans.txt and robots.txt files
Create dynamic sitemap, humans.txt and robots.txt files ... To help search engines like Bing and Google index your website you can use sitemaps...
Read more >
Dynamic Sitemap URL in robots.txt file - Stack Overflow
In any case, make sure to send the correct Content-Type for this file. Some servers automatically select a content type based on the...
Read more >
Can the files robots.txt and sitemap.xml be dynamic through ...
Sitemap.xml files are static and only updates make them dynamic - they do not updating in real time. It's possible of cause to...
Read more >
How to add SITEMAP and robots.txt to Next.js application (fast ...
Sitemap.xml and robots. txt are important for SEO. We will use Next.js API Routes for generating sitemap dynamically every time user (or ...
Read more >
Add Your Sitemap To Your Robots.txt File - WooRank
The Robots.txt file is a simple text file that is placed on your site's root directory. This file uses a set of instructions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found