How can I add a trailing slash to TYPO3 v9 URLs?

后端 未结 4 451
庸人自扰
庸人自扰 2021-01-31 22:51

When updating from TYPO3 8.7 to TYPO3 9.5 you might drop the realurl extension in favor for the new routing feature.

But you might notice, that realurl appended a / to a

4条回答
  •  日久生厌
    2021-01-31 23:12

    To always add an appending /, you can create yourself a route enhancer decorator and put it in your site package.

    Create a file in your site package under Classes/Routing/Enhancer/ForceAppendingSlashDecorator.php with the content:

    all() as $route) {
                $route->setOption('_decoratedRoutePath', '/' . trim($routePath, '/'));
            }
        }
    
        /**
         * {@inheritdoc}
         */
        public function decorateForGeneration(RouteCollection $collection, array $parameters): void
        {
            foreach ($collection->all() as $routeName => $existingRoute) {
                $existingRoutePath = rtrim($existingRoute->getPath(), '/');
                $existingRoute->setPath($existingRoutePath . '/');
            }
        }
    }
    

    Please replace set the correct namespace matching your site package.

    To register your route enhancer, add the line to your ext_localconf.php:

    $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['enhancers']['ForceAppendingSlash'] = \MyVendor\SitePackage\Routing\Enhancer\ForceAppendingSlashDecorator::class;
    

    As a last step, put the following code into your site configuration yaml file:

    routeEnhancers:
      PageTypeSuffix:
        type: ForceAppendingSlash
    

    After this adjustments, TYPO3 will always add an appending / to your URLs so the new URLs will match the old ones created by realurl.

提交回复
热议问题