joomla-cms
joomla-cms copied to clipboard
[5.1] SEF: Implementing trailing slash behavior
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
- Apply the PR
- Check that no URLs changed
- Edit libraries/src/Router/SiteRouter.php and change line 466 to
$uri->setPath($uri->getPath() . '/' . $tmp . '/'); - See that all URLs now contain a trailing slash.
- Go to the SEF system plugin in the backend and set the setting to remove the trailing slash.
- See that all URLs now don't contain a trailing slash.
- Revert the change from step 3.
- Change the setting in the SEF plugin to always add a trailing slash.
- See that all URLs now contain a traling slash again.
- Set the second option to enforce the behavior with a 301 redirect.
- Go to the frontend again and either add or remove the trailing slash, depending on your setting, in your browser bar.
- 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
- 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~
- If accepted dont you need to update the installation and the configuration.php.dist
- What happened to the requirement for all new "features" to be accompanied with documentation
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.
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.
~Tested with both of the following~
~In both cases with the sample joomla data I observed no trailing slash in the url~
Did you read that this PR depends on #42692 ?
no I didnt see that
I have not tested this item.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.
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.
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.
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.
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?
Back to pending
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.
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.
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.
RTC
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.
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.
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.
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.
RTC
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.
This should be retested as there has been a change
After some discussions, we decided to switch this to use 301 redirects instead of 303s.
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.
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.
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.
RTC
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42702.
Link to documentation has been added.
Thank you @Hackwar and for testing and support @SniperSister @viocassel @richard67
Thank you!
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.
You're welcome. ;-)