Bug #86557
closedrouteEnhancers: Routing ending Slash is double
100%
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
Updated by Daniel Dorndorf about 6 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('/');
}
}
}
}
Updated by Christian Knauf about 6 years ago
- Priority changed from Should have to Must have
Updated by Matthias Krappitz about 6 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
Updated by Matthias Krappitz about 6 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!
Updated by Susanne Moog about 6 years ago
- Sprint Focus set to On Location Sprint
Updated by Edward A. Gabdullin about 6 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
Updated by Jesper Mathiasen about 6 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.
Updated by Gerrit Code Review almost 6 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
Updated by Ralf Merz almost 6 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?
Updated by Gerrit Code Review almost 6 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
Updated by Gerrit Code Review almost 6 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
Updated by Gerrit Code Review almost 6 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
Updated by Gerrit Code Review almost 6 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
Updated by Anonymous almost 6 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset a83df28114687682972574480c62c2a8944ac07f.