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

Issue fork drupal-3066086

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nikunjkotecha created an issue. See original summary.

nikunjkotecha’s picture

Status: Active » Needs review
StatusFileSize
new761 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 3066086-2.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

paladyn’s picture

StatusFileSize
new771 bytes

Allow saving trailing slash in PathAlias entity.

paladyn’s picture

Status: Needs work » Needs review

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cilefen’s picture

Category: Support request » Feature request
Status: Needs review » Needs work
Issue tags: +Needs tests

This 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.

elber’s picture

Assigned: Unassigned » elber
elber’s picture

Assigned: elber » Unassigned
Status: Needs work » Needs review
StatusFileSize
new777 bytes

Hello I fixed the coding standard's error, but I not did the tests

cilefen’s picture

Status: Needs review » Needs work

Thanks 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.

elber’s picture

Assigned: Unassigned » elber

Hello @cilefen do you have any suggestion about the inline comment, please? I will try to work on the tests

elber’s picture

Assigned: elber » Unassigned

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

damiaosj’s picture

Hi! I'll try to work on this one.

damiaosj’s picture

StatusFileSize
new7.63 KB

Hello 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 :) .

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.