Blame view

frontend/components/SeoComponent.php 1.07 KB
8afa1bf2   Administrator   29.06.16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  <?php
  namespace frontend\components;
  
  
  use Yii;
  use yii\base\BootstrapInterface;
  
  class SeoComponent implements BootstrapInterface
  {
  
      public function bootstrap($app)
      {
          \Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function($event) {
              $array = ['%21'=>'!','%22'=>'"','%23'=>'#','%24'=>'$','%25'=>'%','%26'=>'&','%27'=>'\'','%28'=>'(','%29'=>')','%2a'=>'*','%2b'=>'+','%2c'=>',','%2d'=>'-','%2e'=>'.','%2f'=>'/','%3a'=>':','%3b'=>';','%3c'=>'<','%3d'=>'=','%3e'=>'>','%3f'=>'?','%40'=>'@','%5b'=>'[','%5c'=>'\\','%5d'=>']','%5e'=>'^','%5f'=>'_','%60'=>'`','%7b'=>'{','%7c'=>'|','%7d'=>'}','%7e'=>'~'];
              $url = mb_strtolower (\Yii::$app->request->url);
  
              $continue = true;
  
              foreach($array as $sym=>$sym_row){
                  if(strpos($url, $sym)){
                      $url = str_replace($sym, $sym_row, $url);
                      $continue = false;
  
                  }
              }
  
              if(!$continue){
                  \Yii::$app->getResponse()->redirect($url);
              }
  
          });
          return $app;
      }
  
  }