diff --git a/common/components/Request.php b/common/components/Request.php index c6c47a8..98a8adf 100755 --- a/common/components/Request.php +++ b/common/components/Request.php @@ -15,6 +15,7 @@ class Request extends \yii\web\Request { + return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl; } diff --git a/frontend/components/SeoComponent.php b/frontend/components/SeoComponent.php new file mode 100644 index 0000000..78341b1 --- /dev/null +++ b/frontend/components/SeoComponent.php @@ -0,0 +1,35 @@ +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; + } + +} \ No newline at end of file diff --git a/frontend/config/main.php b/frontend/config/main.php index 98c26a3..5379da0 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -9,7 +9,10 @@ $params = array_merge( return [ 'id' => 'app-frontend', 'basePath' => dirname(__DIR__), - 'bootstrap' => ['log'], + 'bootstrap' => [ + + 'frontend\components\SeoComponent', + ], 'controllerNamespace' => 'frontend\controllers', 'components' => [ 'authManager' => [ diff --git a/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index 1eb7ef2..fd6f621 100755 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -197,68 +197,49 @@ class Seo extends Widget $sort = \Yii::$app->request->get('sort', []); $paginate = \Yii::$app->request->get('page', []); - $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){ - if(strpos($url, $sym)){ - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => 'noindex,nofollow' - ]); + if (!empty($meta)) { - $continue = false; - break; + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => $meta + ]); - } - } + } else if(!empty($filter['special'])){ + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'noindex,follow' + ]); - if($continue){ - if (!empty($meta)) { - - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => $meta - ]); - - } else if(!empty($filter['special'])){ - - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => 'noindex,follow' - ]); - - } else if ( - isset($filter['brands']) && count($filter['brands']) > 1 - || isset($filter['options']["pol"]) && count($filter['options']["pol"]) > 1 - || isset($filter['options']["naznacenie"]) && count($filter['options']["naznacenie"]) > 1 - || isset($filter['options']["god"]) && count($filter['options']["god"]) > 1 - - ) { - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => 'noindex,nofollow' - ]); - - } else if ( - isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) >= 4 - || isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) > 4 - || !empty($sort) || !empty($paginate) || isset($filter['prices']) - ) { - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => 'noindex,follow' - ]); - } else { + } else if ( + isset($filter['brands']) && count($filter['brands']) > 1 + || isset($filter['options']["pol"]) && count($filter['options']["pol"]) > 1 + || isset($filter['options']["naznacenie"]) && count($filter['options']["naznacenie"]) > 1 + || isset($filter['options']["god"]) && count($filter['options']["god"]) > 1 - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => 'index,follow' - ]); - } + ) { + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'noindex,nofollow' + ]); + + } else if ( + isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) >= 4 + || isset($filter['options']) && count($filter['options'], COUNT_RECURSIVE) > 4 + || !empty($sort) || !empty($paginate) || isset($filter['prices']) + ) { + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'noindex,follow' + ]); + } else { + + $this->getView()->registerMetaTag([ + 'name' => 'robots', + 'content' => 'index,follow' + ]); } -- libgit2 0.21.4