Commit ddd0f5b9595a0fc62cd56edad545aa4a6f0b7495

Authored by Timur Kastemirov
1 parent a40d5f4b

robots txt

.gitignore
... ... @@ -37,3 +37,5 @@ phpunit.phar
37 37 /composer.lock
38 38 storage/*
39 39 !storage/.gitignore
  40 +
  41 +/frontend/web/robots.txt
40 42 \ No newline at end of file
... ...
.htaccess
... ... @@ -16,7 +16,7 @@ AddDefaultCharset utf-8
16 16 RewriteRule ^admin(.*) /backend/web/$1 [L]
17 17  
18 18 RewriteCond %{REQUEST_FILENAME} robots.txt
19   - RewriteRule . /frontend/web/index.php [L]
  19 + RewriteRule . robots.txt
20 20  
21 21 # if a directory or a file of the uploads folder exists, use the request directly
22 22 RewriteCond %{REQUEST_URI} ^/storage
... ...
backend/controllers/SettingsController.php
... ... @@ -76,11 +76,21 @@
76 76 */
77 77 public function actionRobots()
78 78 {
  79 + /**
  80 + * @var Settings $model
  81 + */
79 82 $model = $this->findSettings();
80 83 $model->scenario = Settings::SCENARIO_ROBOTS;
81   -
  84 +
  85 + $robotsTxt = fopen(\Yii::getAlias("@frontend/web/robots.txt"), "w+");
  86 +
82 87 if ($model->load(\Yii::$app->request->post()) && $model->save()) {
83   - \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved'));
  88 +
  89 + if (fwrite($robotsTxt, $model->robots)){
  90 + \Yii::$app->session->setFlash('success', \Yii::t('core', 'Robots saved'));
  91 + fclose($robotsTxt);
  92 + }
  93 +
84 94 }
85 95  
86 96 return $this->render(
... ...
backend/web/robots.txt deleted
1   -User-agent: *
2   -Disallow: /
frontend/web/robots.txt
1   -User-agent: *
2   -Disallow:
3 1 \ No newline at end of file
  2 +User-agent: Google
  3 +Disallow: 123423413
... ...