Zend框架-如何制作robots.txt文件


Zend framework - how can i make the robots.txt file?

Zend framework 2x如何制作http://www.example.com/robots.txt?我在引导程序中有以下内容,但它无法理解"robots.txt"只有在我转到http://www.example.com/robots 时才有效

$route = Http'Segment::factory(array(
  'route' => '/robots[/:action]',
  'defaults' => array(
    'controller' => 'Application'Controller'Sitemap',
    'action' => 'index'
  ),
));
$router->addRoute('robots', $route, null);

'route' => '/robots.txt',之后添加.txt并移除[/:action]

所以你的代码应该是这样的。

    $route = Http'Segment::factory(array(
        'route' => '/robots.txt',
        'defaults' => array(
            'controller' => 'Application'Controller'Sitemap',
            'action' => 'index'
        ),
    ));
    $router->addRoute('robots', $route, null);

编辑:我知道有些人会希望它在磁盘上是物理的,但这样你就有了一个dynamiccrobots.txt文件,你可以用数据库中的东西来填充它。

第2版:是的,我知道你可以把它写在磁盘上,但有很多方法可以做到这一点。

如果您想链接到www.example.com/robots.txt,只需将此robots..txt文件保存到公用文件夹

1)将robots.txt添加到物理路径

您只需在公共路径中添加一个物理robots.txt文件即可。ZF2不会将流量重新路由到公共路径中的现有文件。

因此,如果您将文件放入/public/robots.txt中,则对以下内容的请求将简单地加载文件:

http://www.example.com/robots.txt

2)确保robots.txt有内容

该文件需要内容,否则无法工作
例如:

User-agent: *
Disallow: /

3)检查重写规则

如果它仍然不起作用,您应该检查您的重写规则(.htaccessweb.config文件)是否根据ZF2文档

中的规范进行了配置