可以在robots.txt中使用相对站点地图网址吗?

Eas*_*der 181 sitemap seo robots.txt

在robots.txt中,我可以为站点地图文件编写以下相对URL吗?

sitemap: /sitemap.ashx
Run Code Online (Sandbox Code Playgroud)

或者我必须使用站点地图文件的完整(绝对)URL,例如:

sitemap: http://subdomain.domain.com/sitemap.ashx
Run Code Online (Sandbox Code Playgroud)

为什么我想知道:

  • 我拥有一个新的博客服务www.domain.com,允许用户在accountname.domain.com上发布博客.
  • 我使用通配符,因此所有子域(帐户)都指向:"blog.domain.com".

在blog.domain.com中,我放了robots.txt让搜索引擎找到站点地图.但是,由于通配符,所有用户帐户共享相同的robots.txt文件.这就是为什么我不能使用第二种方法.而目前我不能使用url重写txt文件.(我想IIS的更高版本可以处理这个?)

uno*_*nor 308

根据sitemaps.org上的官方文档,它需要是一个完整的URL:

您可以使用robots.txt文件指定站点地图的位置.为此,只需添加以下行,包括站点地图的完整URL:

Sitemap: http://www.example.com/sitemap.xml
Run Code Online (Sandbox Code Playgroud)

  • 请注意@unor的示例有:带有大写字母S的站点地图.这很重要,因为Robots.txt区分大小写. (29认同)
  • 关于案例的主题,[robotstxt.org](http://www.robotstxt.org/robotstxt.html)指定了名为`robots.txt`的文件,没有大写R. (17认同)
  • @Shams:站点地图中列出的URL必须使用与站点地图文件相同的协议和相同的主机.如果您的站点在`http`*和*`https`下可用,则[您应该只提供一个站点地图(使用规范变体)](http://stackoverflow.com/a/34835383/1591669). (4认同)

小智 7

Google 抓取工具不够智能,它们无法抓取相对 URL,这就是为什么始终建议使用绝对 URL 以获得更好的可抓取性和可索引性。

因此,您不能使用此变体

> sitemap: /sitemap.xml
Run Code Online (Sandbox Code Playgroud)

推荐的语法是

Sitemap: https://www.yourdomain.com/sitemap.xml
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 不要忘记将“站点地图”中的第一个字母大写
  • 不要忘记在“站点地图:”之后添加空格