diff --git a/Classes/BlacklistTrait.php b/Classes/BlacklistTrait.php new file mode 100644 index 0000000..209cf35 --- /dev/null +++ b/Classes/BlacklistTrait.php @@ -0,0 +1,41 @@ +getPath(); + foreach ($this->blacklist as $rawPattern => $active) { + $pattern = '/' . str_replace('/', '\/', $rawPattern) . '/'; + if ($active === true && preg_match($pattern, $path) === 1) { + return true; + } + } + + return false; + } +} diff --git a/Classes/Router.php b/Classes/Router.php index 7a33778..c7af187 100644 --- a/Classes/Router.php +++ b/Classes/Router.php @@ -2,7 +2,7 @@ namespace Yeebase\SEO\Routing; /** - * This file is part of the Yeebase.Readiness package. + * This file is part of the Yeebase.SEO.Routing package. * * (c) 2018 yeebase media GmbH * @@ -17,6 +17,8 @@ class Router extends \Neos\Flow\Mvc\Routing\Router { + use BlacklistTrait; + /** * Resolves the current uri and ensures that a trailing slash is present * @@ -28,8 +30,7 @@ public function resolve(ResolveContext $resolveContext): UriInterface /** @var Uri $uri */ $uri = parent::resolve($resolveContext); - $info = pathinfo($uri); - if (!isset($info['extension'])) { + if ($this->matchesBlacklist($uri) === false && isset(pathinfo($uri)['extension']) === false) { // $uri needs to be reparsed, because the path often contains the query $parsedUri = new Uri((string)$uri); $parsedUri->setPath(rtrim($parsedUri->getPath(), '/') . '/'); diff --git a/Classes/RoutingComponent.php b/Classes/RoutingComponent.php index 377e916..300a241 100644 --- a/Classes/RoutingComponent.php +++ b/Classes/RoutingComponent.php @@ -2,7 +2,7 @@ namespace Yeebase\SEO\Routing; /** - * This file is part of the Yeebase.Readiness package. + * This file is part of the Yeebase.SEO.Routing package. * * (c) 2018 yeebase media GmbH * @@ -18,6 +18,8 @@ class RoutingComponent extends \Neos\Flow\Mvc\Routing\RoutingComponent { + use BlacklistTrait; + /** * The original routing component uses the concret router, not the interface * so it has to be overwritten here @@ -41,11 +43,11 @@ class RoutingComponent extends \Neos\Flow\Mvc\Routing\RoutingComponent public function handle(ComponentContext $componentContext) { $uri = $componentContext->getHttpRequest()->getUri(); + $path = $uri->getPath(); - if ($this->configuration['enable'] === true && $uri->getPath()[-1] !== '/') { - $info = pathinfo($uri); - if (!isset($info['extension'])) { - $uri->setPath($uri->getPath() . '/'); + if ($this->configuration['enable'] === true && $path[-1] !== '/') { + if ($this->matchesBlacklist($uri) === false && isset(pathinfo($uri)['extension']) === false) { + $uri->setPath($path . '/'); $response = $componentContext->getHttpResponse(); $response->setStatus($this->configuration['statusCode']); $response->setHeader('Location', (string) $uri); diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 3a009fe..abcef52 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -4,6 +4,8 @@ Yeebase: redirect: enable: TRUE statusCode: 303 + blacklist: + '/neos/.*': TRUE Neos: Flow: