Blame view

frontend/components/SeoComponent.php 1.22 KB
4253cbec   root   first commit
1
2
3
4
5
6
7
8
9
10
11
12
  <?php
  namespace frontend\components;
  
  
  use Yii;
  use yii\base\BootstrapInterface;
  
  class SeoComponent implements BootstrapInterface
  {
  
      public function bootstrap($app)
      {
4d5dbae3   Administrator   big commti
13
14
15
16
17
18
19
20
21
22
23
24
25
          if(\Yii::$app->request->isGet) {
              \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;
                  
                      }
4253cbec   root   first commit
26
                  }
4d5dbae3   Administrator   big commti
27
28
29
30
31
32
33
          
                  if(!$continue){
                      \Yii::$app->getResponse()->redirect($url);
                  }
              });
          }
          
4253cbec   root   first commit
34
35
36
37
          return $app;
      }
  
  }