Ad

TYPO3 - Force Trailing-slashes

In ddev / TYPO3 / .htaccess - redirect all http -> https Krystian Szymukowicz already gave the solution on how to redirect all http to https in ddev, thx a lot once more!

Now I face the problem of trailing slash and non-trailing slash.

In the TYPO3 site config.yaml I have set

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: /
    index: ''
    map:
      /: 0

That works fine and TYPO3 creates the URLs always with a trailing slash eg. in menus or when linking in the TYPO3 backend. But the pages are also accessible without the trailing slashes which I'm afraid of duplicate content interpretation.

how can I force the trailing slash if someone calls the url without trailing slash? eg. by entering the url manually https://domain.tld/some-site

Ad

Answer

That can be solved via a .htaccess rule:

RewriteRule ^([^\.]*[^/])$ https://%{HTTP_HOST}/$1/ [L,R=301]

If you have mixed content (http/https), you need to further adapt the RewriteRule.

Ad
source: stackoverflow.com
Ad