public function createDefaultEntity() { $tree = new SiteTree(); $tree->setSiteHomePageID(HOME_CID); $locale = new Locale(); $locale->setLanguage('en'); $locale->setCountry('US'); $locale->setSiteTree($tree); $site = new Site($this->config); $site->setSiteHandle('default'); $site->setIsDefault(true); $tree->setLocale($locale); return $site; }
/** * If we have redirect to canonical host enabled, we need to honor it here. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleCanonicalURLRedirection(SymfonyRequest $r, Site $site) { $globalConfig = $this['config']; $siteConfig = $site->getConfigRepository(); if ($globalConfig->get('concrete.seo.redirect_to_canonical_url') && $siteConfig->get('seo.canonical_url')) { $requestUri = $r->getUri(); $path = parse_url($requestUri, PHP_URL_PATH); $trailingSlash = substr($path, -1) === '/'; $url = UrlImmutable::createFromUrl($requestUri, $trailingSlash); $canonical = UrlImmutable::createFromUrl($siteConfig->get('seo.canonical_url'), (bool) $siteConfig->get('seo.trailing_slash')); // Set the parts of the current URL that are specified in the canonical URL, including host, // port, scheme. Set scheme first so that our port can use the magic "set if necessary" method. $new = $url->setScheme($canonical->getScheme()->get()); $new = $new->setHost($canonical->getHost()->get()); $new = $new->setPort($canonical->getPort()->get()); // Now we have our current url, swapped out with the important parts of the canonical URL. // If it matches, we're good. if ($new == $url) { return null; } // Uh oh, it didn't match. before we redirect to the canonical URL, let's check to see if we have an SSL // URL if ($siteConfig->get('seo.canonical_ssl_url')) { $ssl = UrlImmutable::createFromUrl($siteConfig->get('seo.canonical_ssl_url')); $new = $url->setScheme($ssl->getScheme()->get()); $new = $new->setHost($ssl->getHost()->get()); $new = $new->setPort($ssl->getPort()->get()); // Now we have our current url, swapped out with the important parts of the canonical URL. // If it matches, we're good. if ($new == $url) { return null; } } $response = new RedirectResponse($new, '301'); return $response; } }