svetamor/robots_component

create a file robots.txt

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.1 2019-08-09 20:18 UTC

This package is auto-updated.

Last update: 2024-05-12 08:51:11 UTC


README

В конфигурации прописать (пример):

'container' => [
    'definitions' => [
        \app\vendor\svetamor\robots\interfaces\ICreatingFile::class => [
            'class' => \app\vendor\svetamor\robots\CreatingTxt::class, 
            'filePath' => '/robots.txt',
        ],
    ],
],    
'modules' => [
        'robots' => [
            'class' => '\app\modules\Module',
            'components'    => [
                'robotsComponent' => [
                    'class' => \app\vendor\svetamor\robots\RobotsComponent::class,
                    'userAgent' => [
                        '*' => [
                            'Disallow' => [
                                '/articles',
                                '/logs',
                            ],
                            'Allow' => [
                                //..
                            ],
                        ],
                        'WebBot' => [
                            'Disallow' => [
                                '/',
                            ],
                        ],
                    ],
                    'host' => 'site.ru',
                    'sitemap' => 'http://site.ru/sitemap.xml',
                ],
            ],
        ],
    ],

в контроллере:

$module = \Yii::$app->getModule('robots');
    
$response = \Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$response->headers->set('Content-Type', 'text/plain');
    
return $module->robotsComponent->render();