robots.txt - 需要停止对自定义构建 CMS 的 URL 参数进行索引
问题描述
我希望 Google 忽略这样的 URL:
https://www.example.com/blog/category/web-development?page=2
当我的链接在 Google 中被索引时,我需要停止索引它们。我应该使用什么代码来不索引它们?
这是我的刮匙robots.txt
文件:
Disallow: /cgi-bin/
Disallow: /scripts/
Disallow: /privacy
Disallow: /404.html
Disallow: /500.html
Disallow: /tweets
Disallow: /tweet/
我可以用它来禁止它们吗?
Disallow: /blog/category/*?*
解决方案
使用 robots.txt,可以防止抓取,不一定要索引。
如果您想禁止 Google 抓取网址
- 其路径以
/blog/category/
, 和 - 包含查询组件(例如
?
,、、、?page
等?page=2
)?foo=bar&page=2
那么你可以使用这个:
Disallow: /blog/category/*?
最后不需要另一个*
,因为Disallow
值代表URL的开始(从路径开始)。
但请注意,并非所有机器人都支持这一点。根据最初的 robots.txt 规范,*
没有特殊含义。符合要求的机器人会按字面意思解释上述行(*
作为路径的一部分)。如果您只遵循原始规范中的规则,则必须列出每一次出现:
Disallow: /blog/category/c1?
Disallow: /blog/category/c2?
Disallow: /blog/category/c3?
推荐阅读
- sql - SQL:在日期范围内每月生成记录
- java - 将其存储为 URL 时,图像未从 SQLite 显示
- javascript - 克隆模型后,Backbone get set 抛出错误?
- typo3-8.x - Powermail (6.0.0) 中基于字符串的动态接收器
- jquery - jQuery 可排序 - 创建时
- java - 在 Java 中查找 4 个 CheckBox 的有序选择
- django - 如何将 Python 变量传递给 Django 中另一个应用程序中的模板
- node.js - 未找到 Google Calendar API 错误
- php - 尝试访问 Apache 上的文件时权限被拒绝
- powerbi - 在 Power Query M 函数中声明变量