joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[5.1] SEF: Implementing trailing slash behavior

Open Hackwar opened this issue 1 year ago • 26 comments
trafficstars

Summary of Changes

Joomla has been improving its SEO performance constantly and one issue which is still open is the behavior of trailing slashes in URLs. Right now, Joomla has largely been following a no-trailing-slashes policy, however we never enforced this. At the same time, some SEO people wanted to have trailing slashes on all URLs. This PR introduces this feature.

This introduces 2 new settings in the SEF system plugin. The first setting lets you decide if you want to have a trailing slash, no trailing slash or no special behavior (which is the b/c setting). Depending on the setting, it either adds or removes all trailing slashes.

The second setting is available when one of the former options is set and redirects a GET request with missing or trailing slash to the "correct" URL with a 301 depending on the other option.

This PR depends on #42692.

I'd like to thank djumla GmbH for sponsoring this feature.

Testing Instructions

  1. Apply the PR
  2. Check that no URLs changed
  3. Edit libraries/src/Router/SiteRouter.php and change line 466 to $uri->setPath($uri->getPath() . '/' . $tmp . '/');
  4. See that all URLs now contain a trailing slash.
  5. Go to the SEF system plugin in the backend and set the setting to remove the trailing slash.
  6. See that all URLs now don't contain a trailing slash.
  7. Revert the change from step 3.
  8. Change the setting in the SEF plugin to always add a trailing slash.
  9. See that all URLs now contain a traling slash again.
  10. Set the second option to enforce the behavior with a 301 redirect.
  11. Go to the frontend again and either add or remove the trailing slash, depending on your setting, in your browser bar.
  12. See that Joomla redirected you to the same page with the correct URL again.

Link to documentations

Please select:

  • [X] Documentation link for docs.joomla.org: https://docs.joomla.org/Search_Engine_Friendly_URLs

  • [ ] No documentation changes for docs.joomla.org needed

  • [ ] Pull Request link for manual.joomla.org:

  • [ ] No documentation changes for manual.joomla.org needed

Hackwar avatar Jan 23 '24 09:01 Hackwar

  1. Instead of adding another option which a large % of users will never use why not simply do this in the htaccess. ~2. the description is confusing "Remove unneeded index.php from URLs" because it sounds the same as the existing option which removes index.php~
  2. If accepted dont you need to update the installation and the configuration.php.dist
  3. What happened to the requirement for all new "features" to be accompanied with documentation

brianteeman avatar Jan 23 '24 20:01 brianteeman

To 1.: it is a difference if we output wrong URLs and then redirect in the htaccess or do it correct right away. Yes, the redirect could be done in the htaccess, but that requires error prone actions from the user, while this here is the simpler solution.

To 2.: no, since these options are not stored in the configuration.php.

To 3.: the PR is not merged yet, is it. 😉 Documentation is on its way and will be combined with the other 2 router related PRs.

Hackwar avatar Jan 23 '24 21:01 Hackwar

I have tested this item :red_circle: unsuccessfully on 131eafeba08719bc4b6b1899004931399d554975


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

brianteeman avatar Jan 23 '24 22:01 brianteeman

~Tested with both of the following~

~In both cases with the sample joomla data I observed no trailing slash in the url~

brianteeman avatar Jan 23 '24 22:01 brianteeman

Did you read that this PR depends on #42692 ?

Hackwar avatar Jan 23 '24 22:01 Hackwar

no I didnt see that

brianteeman avatar Jan 23 '24 22:01 brianteeman

I have not tested this item.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

brianteeman avatar Jan 23 '24 22:01 brianteeman

I have tested this item :white_check_mark: successfully on d49ccdf9d47c3cb241e20738e5ed42825ff04286

Work as described!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

SniperSister avatar Feb 13 '24 08:02 SniperSister

I have tested this item :white_check_mark: successfully on d49ccdf9d47c3cb241e20738e5ed42825ff04286


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

viocassel avatar Feb 14 '24 09:02 viocassel

Setting RTC as it has 2 good tests, but setting also the RMDG (release manager decision queue) label because this PR is subject of discussion among maintainers.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 14 '24 10:02 richard67

In the CMS Maintainer meeting we talked about this PR and decided to join the two options into one. So if you decide for one behavior, it automatically also means when the URL is not as expected, it does a redirect to the right one. I made the necessary changes. @SniperSister and @viocassel would you be able to test this again?

Hackwar avatar Feb 14 '24 20:02 Hackwar

Back to pending


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 14 '24 20:02 richard67

I have tested this item :white_check_mark: successfully on baac8cd0bf3236a9b332a38e91ed433800e914ec


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

viocassel avatar Feb 15 '24 08:02 viocassel

I have tested this item :white_check_mark: successfully on baac8cd0bf3236a9b332a38e91ed433800e914ec


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

SniperSister avatar Feb 17 '24 15:02 SniperSister

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 17 '24 15:02 richard67

Back to pending as the PR has received a change. @SniperSister @viocassel Could you test again? Thanks in advance.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 19 '24 10:02 richard67

I have tested this item :white_check_mark: successfully on a9f1b3c6a391840860ba131d12a9ac41e35dffab

Works as expected and fixes the issue caught by Martina


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

SniperSister avatar Feb 19 '24 11:02 SniperSister

I have tested this item :white_check_mark: successfully on a9f1b3c6a391840860ba131d12a9ac41e35dffab

👌


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

viocassel avatar Feb 19 '24 11:02 viocassel

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 19 '24 11:02 richard67

This should be retested as there has been a change

brianteeman avatar Feb 20 '24 09:02 brianteeman

After some discussions, we decided to switch this to use 301 redirects instead of 303s.

Hackwar avatar Feb 20 '24 09:02 Hackwar

Back to pending as there have been made changes. @SniperSister @viocassel Could you test again? Thanks in advance.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 20 '24 11:02 richard67

I have tested this item :white_check_mark: successfully on 74383a3970a892403e2d51808138287f3b6166c7


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

SniperSister avatar Feb 20 '24 12:02 SniperSister

I have tested this item :white_check_mark: successfully on 74383a3970a892403e2d51808138287f3b6166c7


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

viocassel avatar Feb 20 '24 12:02 viocassel

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

richard67 avatar Feb 20 '24 12:02 richard67

Link to documentation has been added.

Hackwar avatar Feb 24 '24 11:02 Hackwar

Thank you @Hackwar and for testing and support @SniperSister @viocassel @richard67

LadySolveig avatar Feb 28 '24 17:02 LadySolveig

Thank you!

Hackwar avatar Feb 28 '24 21:02 Hackwar

Thank you very much for this @Hackwar ! I'm glad it didn't get dismissed.

my 2c on the importance: according to Google's Martin Splitt, who I had a conversation with on this topic late last year, this still counts: https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash?hl=en

tl;dr: Trailing slashes do matter to Google. Traditionally that comes from url w/ trailing slash being seen as directory and url w/o trailing slash as file. Google respects same urls with and without trailing slashes to have different content, even. On the other hand, if e.g. https://mysite.com/blog and https://mysite.com/blog/ show the same content, Google may punish you for duplicate content and even if that's not the case, your "Link Juice" will be split 50/50, so instead of getting one better ranked entry in the SERPs, you get 2 worse.

So even if a large % of users will not actively use it, if there is a default behaviour for either with or without trailing slash, still all users will profit from the SEO impact.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.

pAnd0rASBG avatar Apr 11 '24 10:04 pAnd0rASBG

You're welcome. ;-)

Hackwar avatar Apr 11 '24 11:04 Hackwar