如何在 robots.txt 中禁止服务 api 和多语言网址 [英] How to disallow service api and multilingual urls in robots.txt

查看:37
本文介绍了如何在 robots.txt 中禁止服务 api 和多语言网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要禁止下一个网址:

I need to disallow the next URLs:

  1. service api /_s/user, /_s/place, ... 都以/_s/
  2. 开头
  3. 保存格式:/{language}/save.例如 /{en}/save, /{ru}/save, ...
  1. service api /_s/user, /_s/place, ... All starts with /_s/
  2. save form: /{language}/save. For example /{en}/save, /{ru}/save, ...

注意:大多数 URL 开头都有语言参数:/en/event,...我不想阻止它们.

NOTE: most URLs have language parameter at the beginning: /en/event, ... I don't want to block them.

应该是这样的:(但这是robots.txt格式不允许的)

Should be something like: (but this is not allowed by robots.txt format)

Disallow: /_s/*
Disallow: /:lang/save

推荐答案

robots.txt 中匹配是从左边开始的,所以它匹配任何以 /pattern 开头的内容.

In robots.txt matching is from the left, so it matches anything that begins with /pattern.

/*pattern 这样的通配符匹配任何必须跟在给定 pattern 之后的开头.因此,右侧永远不需要 *(例如 /foo*,因为它等同于 /foo).

The wildcard like /*pattern matches any beginning which must be followed by the given pattern. Therefore * is never needed on the right (e.g. /foo* as it is equivalent to /foo).

所以在你的情况下你可以使用

So in your case you can use

禁止:/_s/

  • 禁止任何以 /_s/ 开头的内容,例如/_s/foo
    • to disallow anything which starts with /_s/ e.g. /_s/foo
    • 禁止:/*save

      • 禁止所有模式,例如 /en/save /foosave/en/save/other
        • to disallow all patterns such as /en/save but also /foosave or /en/save/other
        • 您可以使用 $ 来表示必须以结尾"

          You can use $ to signify "must end with"

          禁止:/*save$

          • 禁止所有模式,例如 /en/save/fr/savenot /en/save/other
查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆