nuxt.js robots.txt文件多重限制每个用户代理

发布于 2025-02-07 23:01:03 字数 510 浏览 2 评论 0原文

使用nuxts nuxt-robots 模块如何配置每个用户代理的多项删除。目前我有:

  robots: () => {
    return {
      UserAgent: '*',
      Disallow: '/search/',

      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`,
    }
  },

但是我需要输出:

User-agent: *
Disallow: /search/
Disallow: /testimonials/

User-agent: MJ12bot
Disallow: /search/
Disallow: /testimonials

Using Nuxts nuxt-robots module how do I configure multipe disallows per user agent. Currently I have :

  robots: () => {
    return {
      UserAgent: '*',
      Disallow: '/search/',

      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`,
    }
  },

but I need to output:

User-agent: *
Disallow: /search/
Disallow: /testimonials/

User-agent: MJ12bot
Disallow: /search/
Disallow: /testimonials

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帝王念 2025-02-14 23:01:03

如果您想要几个元素,则可能需要使用数组。

这样的事情不起作用吗?

robots: () => {
  return [
    {
      UserAgent: '*',
      Disallow: '/search/',
      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`,
    },
    {
      UserAgent: 'MJ12bot',
      Disallow: '/search/',
      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`,
    },
  ]
}

就像阵列方法一样: https://github.com/fengsi-io oio/nuxt-robots #array

If you want several elements, you probably need to use an array.

Isn't something like this working?

robots: () => {
  return [
    {
      UserAgent: '*',
      Disallow: '/search/',
      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`,
    },
    {
      UserAgent: 'MJ12bot',
      Disallow: '/search/',
      Sitemap: (req) => `https://${req.headers.host}/sitemap.xml`,
    },
  ]
}

Like the array approach: https://github.com/fengsi-io/nuxt-robots#array

幼儿园老大 2025-02-14 23:01:03

您可以通过将不允许路径指定为机器人配置中的数组来实现这一目标。

robots: {
  rules: {
    UserAgent: '*',
    Disallow: ['/auth/', '/settings', '/search'],
  },
},

该配置的输出将是:

User-agent: *
Disallow: /auth/
Disallow: /settings
Disallow: /search

You can achieve this by specifying the Disallow paths as an array within the robots configuration.

robots: {
  rules: {
    UserAgent: '*',
    Disallow: ['/auth/', '/settings', '/search'],
  },
},

The output from this configuration will be:

User-agent: *
Disallow: /auth/
Disallow: /settings
Disallow: /search
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文