execut / yii2-robots-txt

基于URL规则的生成robots.txt文件的模块

安装量: 11,775

依赖项: 1

建议者: 0

安全: 0

星标: 8

关注者: 2

分支: 3

开放问题: 0

类型:yii2-extension

1.2.3 2019-05-05 22:01 UTC

This package is auto-updated.

Last update: 2024-09-15 20:07:48 UTC


README

安装

建议通过 composer 安装此扩展。

安装

运行以下命令

$ php composer.phar require execut/yii2-robots-txt "dev-master"

或者在您的 composer.json 文件的 require 部分添加以下内容:

"execut/yii2-robots-txt": "dev-master"

to the require section of your composer.json file.

配置示例

将以下规则添加到应用程序配置中

[
    'components' => [
        'urlManager' => [
            'rules' => [
                ['pattern' => 'robots', 'route' => 'robotsTxt/web/index', 'suffix' => '.txt'],
            ]
        ]
    ],
    'modules' => [
        'robotsTxt' => [
            'class' => 'execut\robotsTxt\Module',
            'components'    => [
                'generator' => [
                    'class' => \execut\robotsTxt\Generator::class,
                    'host' => 'localhost',
                    'sitemap' => 'sitemap.xml',
                    //or generate link through the url rules
                    'sitemap' => [
                        'sitemapModule/sitemapController/sitemapAction',
                    ],
                    'userAgent' => [
                        '*' => [
                            'Disallow' => [
                                'noIndexedHtmlFile.html',
                                [
                                    'notIndexedModule/noIndexedController/noIndexedAction',
                                    'noIndexedActionParam' => 'noIndexedActionParamValue',
                                ]
                            ],
                            'Allow' => [
                                //..
                            ],
                        ],
                        'BingBot' => [
                            'Sitemap' => '/sitemapSpecialForBing.xml',
                            'Disallow' => [
                                //..
                            ],
                            'Allow' => [
                                //..
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
];

配置后,robots.txt文件将通过/robots.txt链接打开

许可证

yii2-robots-txt 采用Apache License Version 2.0发布。有关详细信息,请参阅捆绑的LICENSE.md文件。