为什么我的 Nuxt/vue 页面被 robots.txt 屏蔽了?

问题描述

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

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

我的总体问题是我不确定我是否正确构建了我的脚本部分,因为我的页面没有被 Google 索引。在我的 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/',{
        url: '/groen-planlaegning/',{
        url: '/strategisk-samarbejde/',{
        url: '/blog/',{
        url: '/blog/er-ruteplanlaegning-svaert/',{
        url: '/blog/automatisk-ruteplanlaegning/',{
        url: '/faq/',{
        url: '/contact/',{
        url: '/policies/',}
    ]
  },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',{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. 我尝试在我的站点地图中的所有站点 URL 以及上面显示页面示例的 rel-canonical 中添加一个“/”。
  2. 我已尝试将 robots.txt 的用户更改为 googlebot 以禁用两个页面。在用户被设置为“*”之前,它仍然阻止了一些页面

解决方法

默认情况下,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
},