我即将启动 Ruby on Rails 应用程序,作为最后一项任务,我要设置 robots.txt 文件。我找不到有关如何为 Rails 应用程序正确编写路径的信息。
起始路径是否始终是 Ruby on Rails 应用程序或应用程序文件夹的根路径?我该如何禁止,例如 img 文件夹?
我是否必须按照在 app 文件夹中看到的方式编写路径,或者像路径在网站上的在线外观一样,例如http://example.com/admin ?
最佳答案
您必须将 robots.txt 文件放入 /public
文件夹中。
它可能看起来像 robotstxt.org 中的示例:
The following example "/robots.txt" file specifies that no robots should visit any URL starting with "/cyberworld/map/" or "/tmp/", or /foo.html:# robots.txt for http://www.example.com/ User-agent: * Disallow: /cyberworld/map/ # This is an infinite virtual URL space Disallow: /tmp/ # these will soon disappear Disallow: /foo.html
进一步阅读:
关于ruby-on-rails - Ruby on Rails robots.txt 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18693766/