Some SEO experts expect trailing slash on all the urls, including home page. Currently this is possible for all the urls but home page.
Offending code is in Drupal\Core\Routing\UrlGenerator::generateFromRoute():
if (!empty($options['prefix'])) {
$path = ltrim($path, '/');
$prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
$path = '/' . str_replace('%2F', '/', rawurlencode($prefix)) . $path;
}
Suggested solution
By default $path contains empty string for home page but we can change it to forward slash using OutboundPathProcessor. Respect this and do not remove slash if it is the only thing in $path
Comments
Comment #2
nikunjkotechaComment #5
paladyn commentedAllow saving trailing slash in PathAlias entity.
Comment #6
paladyn commentedComment #11
cilefen commentedThis is evidently a feature request but it was opened as a support request. This needs tests and the comment does not meet the coding standards.
Comment #12
elberComment #13
elberHello I fixed the coding standard's error, but I not did the tests
Comment #14
cilefen commentedThanks for that. I think comments have to be complete sentences, and yes, we still need the test, so this is back to "needs work".
'/' may actually be a defined constant somewhere, but I'm not sure about that.
Comment #15
elberHello @cilefen do you have any suggestion about the inline comment, please? I will try to work on the tests
Comment #16
elberComment #18
damiaosj commentedHi! I'll try to work on this one.
Comment #19
damiaosj commentedHello everyone!
I tried to apply the patches in the comment #2 and #5 and I managed to apply effectively, but the patch in the comment #13 does not... So I took the liberty of creating a new patch containing the PHPCS fixes and also applied the other patches.
I'm still with some doubts because apparently the patches does not solved the problem of the slash in the homepage, and I also didn't understand how and where I should create a test for this... If someone can explain it to me I can go back to this issue again and try to build the necessary tests.
Due to this, I'm leaving the status of the issue in "Needs Work".
Hope have helped :) .