Zend 框架 - 如何制作 robots.txt 文件?
Zend framework - how can i make the robots.txt file?
Zend Framework 2x 我如何制作 http://www.example.com/robots.txt
?
我在 bootstrap 中有关注,但它无法理解 "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);
1) 添加robots.txt
到物理路径。
您可以只在 public 路径中添加物理 robots.txt
文件。 ZF2 不会将流量重新路由到 public 路径中的现有文件。
因此,如果您将文件放在 /public/robots.txt
中,那么对以下内容的请求将简单地加载文件:
http://www.example.com/robots.txt
2) 确保robots.txt
有内容
否则文件需要内容it wont work。
例如:
User-agent: *
Disallow: /
3) 检查你的重写规则
如果还是不行你应该检查你的重写规则(.htaccess
或web.config
文件)是否配置according to the specs in the ZF2 documentation
在 '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);
编辑: 我知道有些人希望它在磁盘上是物理的,但是这样你就有了一个 dynamicrobots.txt 文件,你可以用来自数据库。
Edit2: 是的,我知道您可以将其写入磁盘,但有多种方法可以做到这一点。
如果您想要 link 到 www.example.com/robots.txt 只需将此 robots.txt 文件保存到 public 文件夹
Zend Framework 2x 我如何制作 http://www.example.com/robots.txt
?
我在 bootstrap 中有关注,但它无法理解 "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);
1) 添加robots.txt
到物理路径。
您可以只在 public 路径中添加物理 robots.txt
文件。 ZF2 不会将流量重新路由到 public 路径中的现有文件。
因此,如果您将文件放在 /public/robots.txt
中,那么对以下内容的请求将简单地加载文件:
http://www.example.com/robots.txt
2) 确保robots.txt
有内容
否则文件需要内容it wont work。
例如:
User-agent: *
Disallow: /
3) 检查你的重写规则
如果还是不行你应该检查你的重写规则(.htaccess
或web.config
文件)是否配置according to the specs in the ZF2 documentation
在 '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);
编辑: 我知道有些人希望它在磁盘上是物理的,但是这样你就有了一个 dynamicrobots.txt 文件,你可以用来自数据库。
Edit2: 是的,我知道您可以将其写入磁盘,但有多种方法可以做到这一点。
如果您想要 link 到 www.example.com/robots.txt 只需将此 robots.txt 文件保存到 public 文件夹