diff --git a/frontend/components/UrlManager.php b/frontend/components/UrlManager.php index 0a5d8a7..89a5f65 100644 --- a/frontend/components/UrlManager.php +++ b/frontend/components/UrlManager.php @@ -3,11 +3,13 @@ namespace frontend\components; use artbox\core\models\Alias; + use artbox\core\models\Language; use artbox\core\services\Languages; use yii\helpers\Json; use yii\web\NotFoundHttpException; use yii\web\Request; + /** * Url manager extended to work with aliases and languages * @@ -69,8 +71,12 @@ */ public function parseRequest($request) { - // $this->checkRedirect($request->url); + $redirect = $this->checkRedirect($request->url); + + if ($redirect !== null) { + \Yii::$app->response->redirect("/" . $redirect->value, 301); + } $request = $this->parseLanguage($request); $path=$request->pathInfo; @@ -183,27 +189,37 @@ return $request; } - + /** - * Looks for rule in table(column) `redirect.from` if findes - + * Looks for rule in table(column) + * `redirect.from` if findes - * redirects to `redirect.to` * * @param string $url */ protected function checkRedirect(string $url) { - // $redirect = Redirect::find() - // ->where( - // [ - // 'from' => $url, - // ] - // ) - // ->one(); - // - // if ($redirect) { - // \Yii::$app->response->redirect($redirect->to) - // ->send(); - // } + $url1 = parse_url($url); + + + $string = '{"0":"' . ltrim($url1['path'], "/") . '"'; + if (isset($url1['query'])) { + parse_str($url1['query'], $url1['query']); + $string .= (isset($url1['query']['id'])) + ? ',"id":' . $url1['query']['id'] + : ''; + } + + $string .= '}'; + $alias = Alias::find() + ->where(['route' => $string]) + ->one(); + + return $alias; + + + + } protected function invalidParams($requestParams){ -- libgit2 0.21.4