diff --git a/src/EventSubscriber/GlobalredirectSubscriber.php b/src/EventSubscriber/GlobalredirectSubscriber.php index 70b496a..516287c 100644 --- a/src/EventSubscriber/GlobalredirectSubscriber.php +++ b/src/EventSubscriber/GlobalredirectSubscriber.php @@ -126,7 +126,7 @@ class GlobalredirectSubscriber implements EventSubscriberInterface { } $path_info = $event->getRequest()->getPathInfo(); - if (substr($path_info, -1, 1) === '/') { + if (($path_info !== '/') && (substr($path_info, -1, 1) === '/')) { $path_info = rtrim($path_info, '/'); try { $path_info = $this->aliasManager->getPathByAlias($path_info); @@ -258,6 +258,12 @@ class GlobalredirectSubscriber implements EventSubscriberInterface { // @todo PathMatcher::isFrontPage() doesn't work here for some reason. $front = \Drupal::config('system.site')->get('page.front'); + // Since deslash runs after the front page redirect, check and deslash here + // if enabled. + if ($this->config->get('deslash')) { + $path = rtrim($path, '/'); + } + // This might be an alias. $alias_path = \Drupal::service('path.alias_manager')->getPathByAlias($path); diff --git a/src/Tests/GlobalRedirectTest.php b/src/Tests/GlobalRedirectTest.php index 06e3f03..fc23e2d 100644 --- a/src/Tests/GlobalRedirectTest.php +++ b/src/Tests/GlobalRedirectTest.php @@ -143,10 +143,16 @@ class GlobalRedirectTest extends WebTestBase { $this->config->set('frontpage_redirect', TRUE)->save(); $this->config('system.site')->set('page.front', '/node')->save(); $this->assertRedirect('node', ''); + // Test front page redirects with an alias. \Drupal::service('path.alias_storage')->save('/node', '/node-alias'); $this->assertRedirect('node-alias', ''); + // Front page, with deslashing and alias. + $this->config->set('deslash', TRUE)->save(); + $this->assertRedirect('node-alias/', ''); + $this->config->set('deslash', FALSE)->save(); + $this->config->set('frontpage_redirect', FALSE)->save(); $this->assertRedirect('node', NULL, 'HTTP/1.1 200 OK'); $this->assertRedirect('node-alias', NULL, 'HTTP/1.1 200 OK');