Commit ddd0f5b9595a0fc62cd56edad545aa4a6f0b7495

Authored by Timur Kastemirov
1 parent a40d5f4b

robots txt

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