gpt4 book ai didi

perl - 如何使用 Perl Dancer 服务 robots.txt

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:28:45 26 4
gpt4 key购买 nike

我正在尝试使用 Perl Dancer 网络框架提供 robots.txt。我认为有一个只返回文本的路由会起作用,但它似乎将它包装在 htmlbody 标签中。我假设这不会被抓取工具正确解释为 robots.txt 文件。

知道如何正确地做到这一点吗?

这是我写的路线:


获取 '/robots.txt' => sub {
返回“用户代理:*\nDisallow:/”;
};

提前致谢!

最佳答案

是什么让您认为它被包裹在 HTML 和 BODY 元素中?

use Dancer;

get '/robots.txt' => sub {
return "User-agent: *\nDisallow: /\n";
};

dance;

输出:

>lwp-request -e http://127.0.0.1:3000/robots.txt
200 OK
Server: Perl Dancer 1.3112
Content-Length: 26
Content-Type: text/html
Client-Date: Mon, 29 Apr 2013 05:05:32 GMT
Client-Peer: 127.0.0.1:3000
Client-Response-Num: 1
X-Powered-By: Perl Dancer 1.3112

User-agent: *
Disallow: /

我敢打赌,您正在使用使用呈现器的客户端查看它,该呈现器会在看到 text/html 的 Content-Type header 时添加那些。将内容类型设置为 text/plain 会更合适,并且在您用来查看文件的渲染器中看起来更好。

get '/robots.txt' => sub {
content_type 'text/plain';
return "User-agent: *\nDisallow: /\n";
};

不过,最终,它不应该有任何影响。

关于perl - 如何使用 Perl Dancer 服务 robots.txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16271130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com