Skip to content

Commit

Permalink
#347 - Add support for route target cache parameter and use dispatche…
Browse files Browse the repository at this point in the history
…r redirect method
  • Loading branch information
johanjanssens committed May 18, 2020
1 parent e637b59 commit 0848293
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions code/site/components/com_pages/event/subscriber/redirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,32 @@ public function onAfterApplicationRoute(KEventInterface $event)

if(false !== $route = $router->resolve())
{
if($route->toString(KHttpUrl::AUTHORITY))
{
$dispatcher = $this->getObject('com://site/pages.dispatcher.http');
$response = $dispatcher->getResponse();

//Set the location header
if($route->toString(KHttpUrl::AUTHORITY)) {
//External redierct: 301 permanent
$status = KHttpResponse::MOVED_PERMANENTLY;
}
else
{
} else {
//Internal redirect: 307 temporary
$status = KHttpResponse::TEMPORARY_REDIRECT;
}

//Set the redirect status
$response->setStatus($status);

//Set the cache time
if(isset($route->query['cache']))
{
$response->setMaxAge($route->query['cache']);
unset($route->query['cache']);
}

//Qualify the route
$url = $router->qualify($route);

//Set the location header
$dispatcher = $this->getObject('com://site/pages.dispatcher.http');
$dispatcher->getResponse()->getHeaders()->set('Location', $url);
$dispatcher->getResponse()->setStatus($status);

$dispatcher->send();
$dispatcher->redirect($url);
}
}
}

0 comments on commit 0848293

Please sign in to comment.