public function on_start() { Events::addListener('on_page_view', function ($event) { $request = $event->getRequest(); $url = Url::createFromUrl($request->getUri()); $isSSL = false; $pathMatcher = new PathRequestMatcher(); if ($pathMatcher->matches($request)) { $isSSL = true; } if (!$pathMatcher->matches($request)) { $isSSL = false; } $userMatcher = new UserRequestMatcher(); if ($userMatcher->matches($request)) { $isSSL = true; } if (!$userMatcher->matches($request) && $isSSL === false) { $isSSL = false; } if ($isSSL === true && $request->getScheme() == 'http') { $config_canonical_ssl_url = Config::get('concrete.seo.canonical_ssl_url'); if (strlen($config_canonical_ssl_url)) { $canonical_ssl_url = Url::createFromUrl($config_canonical_ssl_url); $url->setHost($canonical_ssl_url->getHost()); } $url->setScheme('https'); $response = new RedirectResponse($url); } elseif ($isSSL === false && $request->getScheme() == 'https') { $config_canonical_url = Config::get('concrete.seo.canonical_url'); if (strlen($config_canonical_url)) { $canonical_url = Url::createFromUrl($config_canonical_url); $url->setHost($canonical_url->getHost()); } $url->setScheme('http'); $response = new RedirectResponse($url); } if (isset($response)) { $response->send(); exit; } }); }
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $trailing_slashes = $this['config']['concrete.seo.trailing_slash']; $path = $request->getPathInfo(); // If this isn't the homepage if ($path && $path != '/') { // If the trailing slash doesn't match the config, return a redirect response if ($trailing_slashes && substr($path, -1) != '/' || !$trailing_slashes && substr($path, -1) == '/') { $parsed_url = Url::createFromUrl($request->getUri(), $trailing_slashes ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED); $response = new RedirectResponse($parsed_url, 301); $response->setRequest($request); return $response; } } }
/** * @inheritdoc */ public function redirect($to, $code = Response::HTTP_MOVED_PERMANENTLY, $headers = array()) { return RedirectResponse::create($to, $code, $headers); }
public function chooseRedirect() { if (!$this->error) { $this->error = Loader::helper('validation/error'); } $nh = Loader::helper('validation/numbers'); $navigation = Loader::helper('navigation'); $rUrl = false; $u = new User(); // added for the required registration attribute change above. We recalc the user and make sure they're still logged in if ($u->isRegistered()) { if ($u->config('NEWSFLOW_LAST_VIEWED') == 'FIRSTRUN') { $u->saveConfig('NEWSFLOW_LAST_VIEWED', 0); } do { // redirect to original destination if (Session::has('rcID')) { $rcID = Session::get('rcID'); if ($nh->integer($rcID)) { $rc = Page::getByID($rcID); } elseif (strlen($rcID)) { $rcID = trim($rcID, '/'); $rc = Page::getByPath('/' . $rcID); } if ($rc instanceof Page && !$rc->isError()) { $rUrl = $navigation->getLinkToCollection($rc); break; } } // admin to dashboard? $dash = Page::getByPath("/dashboard", "RECENT"); $dbp = new Permissions($dash); //should administrator be redirected to dashboard? defaults to yes if not set. $adminToDash = intval(Config::get('concrete.misc.login_admin_to_dashboard')); if ($dbp->canRead() && $adminToDash) { if (!$rc instanceof Page || $rc->isError()) { $rc = $dash; } $rUrl = $navigation->getLinkToCollection($rc); break; } //options set in dashboard/users/registration $login_redirect_mode = Config::get('concrete.misc.login_redirect'); //redirect to user profile if ($login_redirect_mode == 'PROFILE' && Config::get('concrete.user.profiles_enabled')) { $rUrl = View::url('/members/profile/', $u->getUserID()); break; } //redirect to custom page $login_redirect_cid = intval(Config::get('concrete.misc.login_redirect_cid')); if ($login_redirect_mode == 'CUSTOM' && $login_redirect_cid > 0) { $rc = Page::getByID($login_redirect_cid); if ($rc instanceof Page && !$rc->isError()) { $rUrl = $navigation->getLinkToCollection($rc); break; } } break; } while (false); if ($rUrl) { $r = new RedirectResponse($rUrl); $r->send(); exit; } else { $this->redirect('/'); } } else { $this->error->add(t('User is not registered. Check your authentication controller.')); $u->logout(); } }
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $request_path = $request->getRequestUri(); $parsed_url = Url::createFromUrl($request->getUri()); $url_path = ltrim(parse_url($request_path, PHP_URL_PATH), '/'); if ($url_path != (string) $parsed_url->getPath()) { $response = new RedirectResponse($parsed_url, 301); $response->setRequest($request); return $response; } }
/** * Actually sends a redirect */ protected static function createRedirectResponse($url, $code, $headers) { $r = new RedirectResponse($url, $code, $headers); $r->setRequest(Request::getInstance()); return $r; }
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $url = Url::createFromUrl($request->getUri()); if ($request->getPathInfo() != '/') { if (urldecode((string) $url) != urldecode($request->getUri())) { $response = new RedirectResponse((string) $url, 301); $response->setRequest($request); return $response; } } }
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $parsedUrl = (string) Url::createFromUrl($request->getUri()); if ($request->getPathInfo() != '/') { $parsedUrlWithoutQueryString = strstr($parsedUrl, '?', true) ?: $parsedUrl; $requestUrl = $request->getUri(); $requestUrlWithoutQueryString = strstr($requestUrl, '?', true) ?: $requestUrl; if (urldecode($parsedUrlWithoutQueryString) != urldecode($requestUrlWithoutQueryString)) { $response = new RedirectResponse($parsedUrl, 301); $response->setRequest($request); return $response; } } }
/** * Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9. * * @link http://support.microsoft.com/kb/323308 */ protected function ensureIEOverSSLCompatibility(Symfony\Component\HttpFoundation\Request $request) { return parent::ensureIEOverSSLCompatibility($request); }