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 all urls by default (when you are not using html suffix) The TYPO3 routing feature does not do that by default and there is currently no option in the core to enable this. Why is this a problem? In TYPO3 8.7 you got an URL like www.domain.tld/subpage/. In TYPO3 9.5 the same page be called with the url www.domain.tld/subpage. So even if this is the same page, for search crawlers, this is another URL. TYPO3 does a 307 redirect when calling the URL with an appending /, but you might want to use your old URL structure.
How can I teach TYPO3 to add an appending /?
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:Please replace set the correct namespace matching your site package.
To register your route enhancer, add the line to your
ext_localconf.php
:As a last step, put the following code into your site configuration yaml file:
After this adjustments, TYPO3 will always add an appending / to your URLs so the new URLs will match the old ones created by realurl.
Tim, are you sure about getRoutePathRedecorationPattern()?
For me, it worked in two totally different TYPO3 (v9.5.3) instances in production, but both projects did not work in a ddev-container. There, the slugCandidates have always missed its last char.
Changing the pattern from "all except slash" to "exactly a slash" makes it work.
You can use the PageTypeEnhancer for mapping &type parameter in your site configuration (config.yaml file):
Additional to the answer from Tim Schreiner, i made a condition in the .htaccess file, which redirects urls whithout slashes to the url with trailing slash. Files should not be affected by this condition. Following condition did i add to the .htaccess file: