如何在 robots.txt 中禁止服务 api 和多语言网址 [英] How to disallow service api and multilingual urls in robots.txt
问题描述
我需要禁止下一个网址:
I need to disallow the next URLs:
- service api
/_s/user
,/_s/place
, ... 都以/_s/
开头 - 保存格式:
/{language}/save
.例如/{en}/save
,/{ru}/save
, ...
- service api
/_s/user
,/_s/place
, ... All starts with/_s/
- 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
- 禁止所有模式,例如
/en/save
但也/foosave
或/en/save/other代码>
- to disallow all patterns such as
/en/save
but also/foosave
or/en/save/other
- 禁止所有模式,例如
/en/save
或/fr/save
但not/en/save/other
- to disallow all patterns such as
/en/save
or/fr/save
but not/en/save/other
禁止:/*save
您可以使用 $
来表示必须以结尾"
You can use $
to signify "must end with"
禁止:/*save$
您可以在 Robots.txt 中找到更多关于 robots.txt 的内容:4你应该知道的事情文章
我希望这会有所帮助.
这篇关于如何在 robots.txt 中禁止服务 api 和多语言网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!