Project

General

Profile

Actions

Bug #86557

closed

routeEnhancers: Routing ending Slash is double

Added by Christian Knauf over 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2018-10-03
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
On Location Sprint

Description

If you want to add a "/" at the end of a URL, it will be added twice to the URL in the frontend.

routeEnhancers:
Suffix:
type: PageType
default: /
index: ''
map:
.json: 10

Actions #1

Updated by Christian Knauf over 5 years ago

  • Assignee set to Oliver Hader
Actions #2

Updated by Daniel Dorndorf over 5 years ago

I also had the issue and solved this with a custom page type decorator.

For the trailing slash ROUTE_PATH_DELIMITERS should have / in the array
The class also solves the problem with the startpage generating "/index/" or "index.html" if you force ".html"

PageTypeSuffix:
  type: CustomPageType
  default: '/'
  index: 'index'
  map:
    '/': 0
class CustomPageTypeDecorator extends PageTypeDecorator
{
    public const IGNORE_INDEX = [
        '/index.html',
        '/index/',
    ];

    public const ROUTE_PATH_DELIMITERS = ['.', '-', '_', '/'];

    /**
     * @param \TYPO3\CMS\Core\Routing\RouteCollection $collection
     * @param array $parameters
     */
    public function decorateForGeneration(RouteCollection $collection, array $parameters): void
    {
        parent::decorateForGeneration($collection, $parameters);

        /**
         * @var string $routeName
         * @var \TYPO3\CMS\Core\Routing\Route $route
         */
        foreach ($collection->all() as $routeName => $route) {
            $path = $route->getPath();

            if (true === \in_array($path, self::IGNORE_INDEX, true)) {
                $route->setPath('/');
            }
        }
    }
}
Actions #3

Updated by Wouter Wolters over 5 years ago

  • Assignee deleted (Oliver Hader)
Actions #4

Updated by Christian Knauf over 5 years ago

  • Priority changed from Should have to Must have
Actions #5

Updated by Matthias Krappitz over 5 years ago

Can confirm this problem. No matter how you do it, you end up with trailing "//" instead of trailing "/". Tried the following variants:

routeEnhancers:
    PageType:
        type: PageType
        default: '/'
        map:
            '/': 1

routeEnhancers:
    Suffix:
        type: PageType
        default: '/'
        index: ''
        map:
            '/': 1

routeEnhancers:
    PageTypeSuffix:
        type: PageType
        default: '/'
        index: ''
        map:
            '/': 1
Actions #6

Updated by Matthias Krappitz over 5 years ago

Sven Wappler proposed a simple fix for this double trailing "/" issue to change line 150 of typo3/sysext/core/Classes/Routing/Enhancer/PageTypeDecorator.php from

if ($value !== '' && !in_array($value{0}, static::ROUTE_PATH_DELIMITERS)) {

to
if ($value !== '' && !in_array($value{0}, static::ROUTE_PATH_DELIMITERS) && $value !== '/') {

when the "/" suffix for the urls in the siteconf is as written above. This works for me!

Actions #7

Updated by Susanne Moog over 5 years ago

  • Sprint Focus set to On Location Sprint
Actions #8

Updated by Edward A. Gabdullin over 5 years ago

Matthias Krappitz wrote:

Sven Wappler proposed a simple fix for this double trailing "/" issue to change line 150 of typo3/sysext/core/Classes/Routing/Enhancer/PageTypeDecorator.php from
[...]
to
[...]
when the "/" suffix for the urls in the siteconf is as written above. This works for me!

After this change, XmlSitemap displays links without type=1533906435, for example it should be:

https://domain.name/en/?sitemap=pages&type=1533906435&cHash=a99c2cfce77a538c64e3de0213cf780e

but it turns out
https://domain.name/en/?sitemap=pages&cHash=a99c2cfce77a538c64e3de0213cf780e

P.S. Sorry, an error in the path XmlSitemap appears after adding the suffix:

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

Actions #9

Updated by Jesper Mathiasen over 5 years ago

Another inconsistency is with translations. As default the urls generated will not have a trailing slash:

domain.com/page/subpage

but the top level page for a translation will have a trailing slash:

domain.com/en/

Of course when using '.html' suffixes with the index property set to 'index' this does not pose a problem as it would then look like this:

domain.com/en/index.html

Is the forced trailing slash for a translated index page the desired outcome, i.e. does it have some semantic meaning?

The solution above (https://forge.typo3.org/issues/86557#note-2) solves it for me by creating consistent trailing slashes.

Actions #10

Updated by Gerrit Code Review over 5 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

Actions #11

Updated by Ralf Merz over 5 years ago

Hi,

i´ve just provided a patch with the added trailing slash to the constant as Daniel said in
https://forge.typo3.org/issues/86557#note-2

I use this in my config.yaml (rss and json may be ignored):

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: '/'
    suffix: '/'
    index: 'index'
    map:
      'rss.feed': 13
      '.json': 26
      '/': 0

Would that help to get "trailing slash" on track?

Actions #12

Updated by Gerrit Code Review over 5 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

Actions #13

Updated by Gerrit Code Review over 5 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

Actions #14

Updated by Gerrit Code Review over 5 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59123

Actions #15

Updated by Gerrit Code Review over 5 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59375

Actions #16

Updated by Anonymous over 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #17

Updated by Benni Mack almost 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF