fourlabs/robots-bundle

用于通过注解控制 X-Robots-Tag HTTP 头的 Symfony2 扩展包

安装次数: 21,032

依赖项: 0

建议者: 0

安全性: 0

星级: 1

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2015-09-01 10:20 UTC

This package is auto-updated.

Last update: 2024-09-22 07:54:33 UTC


README

Symfony2 扩展包,通过注解控制 X-Robots-Tag HTTP 头。

Total Downloads License SensioLabsInsight

安装

下载扩展包

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展包的最新版本

$ composer require fourlabs/robots-bundle dev-master

此命令要求您已全局安装 Composer,具体说明请参阅 Composer 文档中的 安装章节

启用扩展包

然后,通过在您的项目的 app/AppKernel.php 文件中添加以下行来启用扩展包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FourLabs\RobotsBundle\FourLabsRobotsBundle(),
    );
}

使用方法

更多详细信息请参阅:https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag#using-the-x-robots-tag-http-header

示例

use FourLabs\RobotsBundle\Configuration\Robots;

/**
 * @Robots(directive="index")
 */
public function showAction()
{
}
use FourLabs\RobotsBundle\Configuration\Robots;

/**
 * @Robots(directive="nofollow", userAgent="googlebot")
 * @Robots(directive="noindex, nofollow" userAgent="otherbot")
 */
public function showAction()
{
}
use FourLabs\RobotsBundle\Configuration\Robots;

/**
 * @Robots(directive="noarchive")
 * @Robots(directive="unavailable_after" value="25 Jun 2010 15:00:00 PST")
 */
public function showAction()
{
}

配置

block_all 设置为 true 以始终将 X-Robots-Tag 头设置为 none。这将阻止所有索引和服务。默认:false

这有助于设置特定于环境的 robots 头,以防止搜索引擎索引开发环境和测试环境。只需在您的 config_dev.yml 和/或 config_test.yml 中放置以下配置即可。

four_labs_robots:
    block_all: true