首页 > 解决方案 > 为什么我的 Nuxt/vue 页面会被 robots.txt 阻止?

问题描述

这不是关于 SEO 最佳实践的问题,而是关于如何在 VUE 中正确设置 config.js 和脚本部分的问题

我已经使用 Vue/Nuxt 构建了我的网站,而之前我在公园里散步时使用 angular,现在正在导致错误。

我的总体问题是我不确定我是否正确构建了我的脚本部分,因为我的页面没有被谷歌索引。在我的 nuxt.config.js 文件中,我构建了我的站点地图、robot.txt 和一些通用元标记。对于每个页面,我都在其脚本部分构建了动态元标记。

Google Search Console 给出了 3 种错误。

  1. 某些页面被我的 robots.txt 屏蔽了
  2. 据说有些页面是重复的 rel-canonical
  3. 检查我的网站时,如果不在 URL 末尾输入“/”,它就无法找到页面。使用 Screaming Frog SEO 工具时也会出现这种情况。

我的假设是我错过了某种形式的重定向,它使爬虫索引页面以“/”结尾,因为这些页面在 Search Console 中被很好地编入索引?

Nuxt.config.js 文件(部分,未显示所有内容)

    head: {
    title: 'NorthArc',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { name: 'language', content: 'da_DK' },
      { name: 'robots', content: 'index, follow' },
      { name: 'og:type', content: 'website' },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
    ]
  },

sitemap: {
    path: '/sitemap.xml',
    hostname: 'https://northarc.dk/',
    routes: [
      {
        url: '/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/team/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/groen-planlaegning/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/strategisk-samarbejde/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/blog/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/blog/er-ruteplanlaegning-svaert/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/blog/automatisk-ruteplanlaegning/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/faq/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/contact/',
        changefreq: 'monthly',
        priority: 1,
      },
      {
        url: '/policies/',
        changefreq: 'monthly',
        priority: 1,
      }
    ]
  },

  robots: {
    UserAgent: 'Googlebot',
    Disallow: ['/roi', '/pricing'],
    Sitemap: 'https://northarc.dk/sitemap.xml',

  },

页面中的脚本部分,据说被阻止 bt robots.txt 并具有重复的 rel-canonical。

    <script>
export default {
  name: 'home',
  head() {
    return {
      title: 'test',
      meta: [
        { 
        hid: 'description', 
        name: 'description', 
        content: 'test', 
        },
        { hid: 'robots', name: 'robots', content: 'index, follow' },
      {hid: 'og-title', property: 'og:title', content: 'Fjern spildtid på vejen og minimere antal kørte kilometer'},
      {hid: 'og-url', property: 'og:url', content: 'https://northarc.dk/groen-planlaegning'},
      {hid: 'og-description', property: 'og:description', content: 'test'},
      {hid: 'og-image', property: 'og:image', content: '/Applications/Northarc_landing/assets/Preview_sløret.jpg'},
      ],
      link: [
      { 
      rel: 'canonical', 
      href: 'https://northarc.dk/groen-planlaegning/' 
      }
    ] 
    }
  }
};
</script>

注释:(更改日志)

  1. 我试图在我的站点地图和上面显示的页面示例的 rel-canonical 中向所有站点 URL 添加一个“/”。
  2. 我试图将 robots.txt 的用户更改为 googlebot 以禁止两个页面。在用户被设置为“*”之前,它仍然阻止了一些页面。

标签: vue.jsseonuxt.jsrobots.txtgoogle-search-console

解决方案


默认情况下,Nuxt 允许每个路由不带或带斜杠,例如:

它可以被爬虫检测为重复内容。
因此,您可以使用“规范”标头定义哪个是主 URL。

但是,如果您只想保留带有斜杠的 URL,则必须通过路由器配置仅允许带有斜杠的路由:

// nuxt.config.js

router: {
  trailingSlash: true
}

请参阅文档https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-router#trailingslash


此外,您不需要在站点地图模块配置中对所有路由进行硬编码,所有静态路由都是自动的,例如:

// nuxt.config.js

sitemap: {
  hostname: 'https://northarc.dk',
  defaults: {
    changefreq: 'monthly',
    priority: 1,
    trailingSlash: true
  },
  exclude: ['roi', 'pricing'],
  trailingSlash: true // if necessary
},

推荐阅读