Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Googlebot无法识别dynamic robots.txt_Php_Laravel_Nginx_Robots.txt_Googlebot - Fatal编程技术网

Php Googlebot无法识别dynamic robots.txt

Php Googlebot无法识别dynamic robots.txt,php,laravel,nginx,robots.txt,googlebot,Php,Laravel,Nginx,Robots.txt,Googlebot,我用laravel创建了一个动态路由,它提供txt响应 它可以在浏览器上运行,但谷歌机器人说没有robots.txt文件 这是我得到的标题: 缓存控制→无缓存 联系→活命 内容配置→内联;filename=“robots.txt” 内容编码→gzip 内容类型→文本/纯文本;字符集=UTF-8 日期→2016年3月23日星期三11:36:44 GMT 服务器→nginx/1.9.12 传输编码→大块 变化→接受编码 这是我的拉威尔路线: Route::get('robots.txt','Tx

我用laravel创建了一个动态路由,它提供txt响应

它可以在浏览器上运行,但谷歌机器人说没有
robots.txt
文件

这是我得到的标题:


缓存控制→无缓存
联系→活命
内容配置→内联;filename=“robots.txt”
内容编码→gzip
内容类型→文本/纯文本;字符集=UTF-8
日期→2016年3月23日星期三11:36:44 GMT
服务器→nginx/1.9.12
传输编码→大块
变化→接受编码

这是我的拉威尔路线:

Route::get('robots.txt','TxtController@robots');

这就是方法:


公共功能机器人(){
return response()->view('txt.robots')->header('Content-Type','text/plain')->header('Content-Disposition','inline;filename=“robots.txt”);
}

我尝试了
内容配置→附件filename=“robots.txt”
但谷歌一直说没有
robots.txt
文件

我试图删除
内容配置
,但仍然无法从Google Web Master Tools中使用(它可以在浏览器上使用)

这是我的nginx配置,可能这里有问题:

```

谢谢。

当我检查HTTP响应头时,它们是:

Cache-Control:private, max-age=0
Content-Encoding:gzip
Content-Length:1574
Content-Type:text/plain
Date:Wed, 23 Mar 2016 12:07:44 GMT
Expires:Wed, 23 Mar 2016 12:07:44 GMT
Last-Modified:Fri, 04 Mar 2016 19:02:51 GMT
Server:sffe
Vary:Accept-Encoding
X-Content-Type-Options:nosniff
X-XSS-Protection:1; mode=block
为什么不跳过
内容处理
标题,只输出带有
内容类型:text/plain
标题的文本

还有

  • 您确定您的robots.txt url可以从外部世界获得吗?也许可以使用代理进行双重检查
  • 您的输出是UTF-8编码的吗

有关更多信息,请参见

内容配置
头用于在浏览器中强制下载文件。它可能会混淆Google bot-尝试在不使用它的情况下提供文件:

public function robots(){
    return response()->view('txt.robots')->header('Content-Type', 'text/plain');
}

我通过添加一个内容长度标题解决了这个问题。代码结果如下所示:

    $response = response()->view('txt.robots')->header('Content-Type', 'text/plain');
    $response->header('Content-Length',strlen($response->getOriginalContent()));

    return $response;

我希望这有帮助。感谢您的回复。

尝试删除“内容处置”、“内联”;这是我的原始代码,但我不为谷歌工作。回答是正确的,但是谷歌网站管理员工具说没有
robots.txt
文件您可以从浏览器访问它吗?还有
robots.txt
内容问题-您必须启用文件本身的访问权限是的,您可以使用浏览器访问,并且我已经验证了其内容。问题在于它不是一个静态文件,而是一个带有文本/普通头的服务器响应。我已经检查了我的nginx配置,它也可以工作。我在尝试使其工作时添加了内容配置。我的原始代码只有一个标题(text/plain),您可以从外部毫无问题地访问/robots.txt,它应该是utf-8,因为标题
内容类型:text/plain;字符集=UTF-8
    $response = response()->view('txt.robots')->header('Content-Type', 'text/plain');
    $response->header('Content-Length',strlen($response->getOriginalContent()));

    return $response;