/** * Checks for alias request * @return Page or null */ public function resolveAlias() { // This is our alias, if any $path = $this->url->getSuggestedTargetPath(); $this->path = $path; //(I) see what the model has for us, aliases only. $result = $this->pageRepo->getPagesAtPath($path, null, null, false, \Cx\Core\ContentManager\Model\Repository\PageRepository::SEARCH_MODE_ALIAS_ONLY); //(II) sort out errors if (!$result) { // no alias return null; } if (!$result['page']) { // no alias return null; } if (count($result['page']) != 1) { throw new ResolverException('Unable to match a single page for this alias (tried path ' . $path . ').'); } $page = current($result['page']); if (!$page->isActive()) { throw new ResolverException('Alias found, but it is not active.'); } $langDir = $this->url->getLangDir(); $frontendLang = defined('FRONTEND_LANG_ID') ? FRONTEND_LANG_ID : null; if (!empty($langDir) && $this->pageRepo->getPagesAtPath($langDir . '/' . $path, null, $frontendLang, false, \Cx\Core\ContentManager\Model\Repository\PageRepository::SEARCH_MODE_PAGES_ONLY)) { return null; } $this->page = $page; $params = $this->url->getParamArray(); if (isset($params['external']) && $params['external'] == 'permanent' || $this->page->isTargetInternal() && preg_match('/[?&]external=permanent/', $this->page->getTarget())) { if ($this->page->isTargetInternal()) { $params = array(); if (trim($this->page->getTargetQueryString()) != '') { $params = explode('&', $this->page->getTargetQueryString()); } $target = \Cx\Core\Routing\Url::fromNodeId($this->page->getTargetNodeId(), $this->page->getTargetLangId(), $params); } else { $target = $this->page->getTarget(); } header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $target); header('Connection: close'); exit; } return $this->page; }