1

我阅读了一些关于 robots.txt 的内容,并且阅读了我应该禁止我的 Web 应用程序中的所有文件夹,但我想允许机器人阅读主页和一个视图(网址例如:www.mywebapp/searchresults - 这是一个codeigniter 路由 - 它是从应用程序/控制器/函数调用的)。

文件夹结构例如是:

-index.php(should be able to read by bots)
-application
  -controllers
    -controller(here is a function which load view)
  -views
-public

我应该像这样创建 robots.txt:

User-agent: *
Disallow: /application/
Disallow: /public/
Allow: /application/controllers/function

或使用类似的路线

User-agent: *
Disallow: /application/
Disallow: /public/
Allow: /www.mywebapp/searchresults

或者也许使用视图?

User-agent: *
Disallow: /application/
Disallow: /public/
Allow: /application/views/search/index.php

谢谢!

4

2 回答 2

1

回答我自己的老问题:

当我们希望允许机器人读取某些页面时,我们需要使用我们的 URL(路由),所以在这种情况下:

Allow: /www.mywebapp/searchresults

在某些情况下,我们还可以通过 HTML 标记(添加到页眉)禁止某些页面:

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

当我们想阻止一些文件夹,即带有图片时,只需执行以下操作:

Disallow: /public/images
于 2017-08-04T19:15:31.953 回答
0

您不会阻止视图文件,因为爬虫无法直接访问该文件。您需要阻止用于访问您的视图的 URL

robots.txt 文件必须放在主机的文档根目录中。它不会在其他地方工作。

If your host is www.example.com, it needs to be accessible at http://www.example.com/robots.txt

要删除您网站的目录或单个页面,您可以将 robots.txt 文件放在服务器的根目录下。创建 robots.txt 文件时,请记住以下几点: 在决定在特定主机上抓取哪些页面时,Googlebot 将遵循 robots.txt 文件中的第一条记录,用户代理以“Googlebot”开头。如果不存在这样的条目,它将服从用户代理为“ ”的第一个条目。此外,Google 通过使用星号为 robots.txt 文件标准引入了更高的灵活性。不允许的模式可能包括“ ”以匹配任何字符序列,模式可能以“$”结尾以指示名称的结尾。

To remove all pages under a particular directory (for example, listings), you'd use the following robots.txt entry:

User-agent: Googlebot
Disallow: /listings
To remove all files of a specific file type (for example, .gif), you'd use the following robots.txt entry:

User-agent: Googlebot
Disallow: /*.gif$ 
To remove dynamically generated pages, you'd use this robots.txt entry:

User-agent: Googlebot
Disallow: /*? 
Option 2: Meta tags

Another standard, which can be more convenient for page-by-page use, involves adding a <META> tag to an HTML page to tell robots not to index the page. This standard is described at http://www.robotstxt.org/wc/exclusion.html#meta.

To prevent all robots from indexing a page on your site, you'd place the following meta tag into the <HEAD> section of your page:

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">

To allow other robots to index the page on your site, preventing only Search Engine's robots from indexing the page, you'd use the following tag:

<META NAME="GOOGLEBOT" CONTENT="NOINDEX, NOFOLLOW">

To allow robots to index the page on your site but instruct them not to follow outgoing links, you'd use the following tag:

<META NAME="ROBOTS" CONTENT="NOFOLLOW">

供进一步参考

https://www.elegantthemes.com/blog/tips-tricks/how-to-create-and-configure-your-robots-txt-file

于 2015-08-22T01:33:42.463 回答