From ddd0f5b9595a0fc62cd56edad545aa4a6f0b7495 Mon Sep 17 00:00:00 2001 From: timur Date: Thu, 9 Nov 2017 12:21:28 +0200 Subject: [PATCH] robots txt --- .gitignore | 2 ++ .htaccess | 2 +- backend/controllers/SettingsController.php | 14 ++++++++++++-- backend/web/robots.txt | 2 -- frontend/web/robots.txt | 4 ++-- 5 files changed, 17 insertions(+), 7 deletions(-) delete mode 100755 backend/web/robots.txt diff --git a/.gitignore b/.gitignore index 2159ca9..88de3bf 100755 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,5 @@ phpunit.phar /composer.lock storage/* !storage/.gitignore + +/frontend/web/robots.txt \ No newline at end of file diff --git a/.htaccess b/.htaccess index cf009bf..5f70064 100755 --- a/.htaccess +++ b/.htaccess @@ -16,7 +16,7 @@ AddDefaultCharset utf-8 RewriteRule ^admin(.*) /backend/web/$1 [L] RewriteCond %{REQUEST_FILENAME} robots.txt - RewriteRule . /frontend/web/index.php [L] + RewriteRule . robots.txt # if a directory or a file of the uploads folder exists, use the request directly RewriteCond %{REQUEST_URI} ^/storage diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php index f81bc22..e8ebc94 100755 --- a/backend/controllers/SettingsController.php +++ b/backend/controllers/SettingsController.php @@ -76,11 +76,21 @@ */ public function actionRobots() { + /** + * @var Settings $model + */ $model = $this->findSettings(); $model->scenario = Settings::SCENARIO_ROBOTS; - + + $robotsTxt = fopen(\Yii::getAlias("@frontend/web/robots.txt"), "w+"); + if ($model->load(\Yii::$app->request->post()) && $model->save()) { - \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved')); + + if (fwrite($robotsTxt, $model->robots)){ + \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved')); + fclose($robotsTxt); + } + } return $this->render( diff --git a/backend/web/robots.txt b/backend/web/robots.txt deleted file mode 100755 index 1f53798..0000000 --- a/backend/web/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: / diff --git a/frontend/web/robots.txt b/frontend/web/robots.txt index 6f27bb6..f82ad64 100755 --- a/frontend/web/robots.txt +++ b/frontend/web/robots.txt @@ -1,2 +1,2 @@ -User-agent: * -Disallow: \ No newline at end of file +User-agent: Google +Disallow: 123423413 -- libgit2 0.21.4