2

HTML 语言中合理使用 meta 标签的 robots 命令

 2 years ago
source link: https://opssh.cn/daima/206.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

HTML 语言中合理使用 meta 标签的 robots 命令

日期:2022年04月04日
·
分类:技术积累
已阅读 85 次

经常在搜索引擎中看到页码页面的排名比首页还高的情况,也经常会看到收录一堆的页码页面,如下图,在页面优化中我们该如何控制呢?其实比较简单就是在页面内判断显示 meta name="robots" content="" 标签即可,同时也可以解决没有设置 robots.txt 文件的问题。

HTML 语言中合理使用 meta 标签的 robots 命令

命令解释

先来看下在 seo优化 中 禁止搜索引擎抓取本页面 和 允许搜索引擎抓取本页面 经常使用到的 content 命令:index、noindex、follow、nofollow,解释如下:

index 命令:搜索引擎允许抓取这个页面

follow 命令:搜索引擎可以从这个页面上找到链接,继续访问抓取其他页面

noindex 命令:搜索引擎不允许抓取这个页面

nofollow 命令:搜索引擎不允许从此页找到链接、拒绝其继续访问页面

组合命令

明白以上命令意思后就可以进行组合 meta 标签中的 robots 了,为了方便明白,下面我列出了四种组合提供给新手理解,组合如下:

允许抓取本页,并顺着本页继续索引其他页面

Markup
<meta name="robots" content="index,follow">

不许抓取本页,但可以顺着本页抓取索引其他页面

Markup
<meta name="robots" content="noindex,follow">

可以抓取本页,但不许顺着本页抓取索引其他页面

Markup
<meta name="robots" content="index,nofollow">

不许抓取本页,也不许顺着本页抓取索引其他页面

Markup
<meta name="robots" content="noindex,nofollow">

演示实例

比如我们在 Zblog 模板中要控制首页分页页面不允许收录并继续索引别的页面,那么我们就要用到 noindex 和 follow 命令,实例操作如下:

<meta name="robots" content="noindex,follow">

但直接使用以上标签,会让首页第一页也不进行抓取,这里就要用到页面判断了,以下实例为首页第一页允许抓取本页并继续索引别的页面,首页其他页面为不许抓取本页但可以索引其他页面,实例操作如下:

// 判断首页是否为第一页,否则其他页面为

{if $type=='index'&&$page=='1'}
  <meta name="robots" content="index,follow">
{else}
  <meta name="robots" content="noindex,follow">
{/if}

// 判断首页是否为第一页,否则其他页面为

其他页面也可通过本方法进行判断显示,比如:分类分页 与 标签分页。

最后总结

从以上实例大致可以得出结论为,首页、分类、标签分页可进行页面判断显示 meta 标签,主要为:noindex 和 follow 命令。

文章页 和 独立专题页 我们可直接使用 index 与 follow,允许抓取本页并继续索引其他页面,如果你有其他页面可以根据自己所需情况进行修改显示。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK