Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] SEF: Enforcing correct SEF URL #42854

Open
wants to merge 8 commits into
base: 5.2-dev
Choose a base branch
from

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented Feb 21, 2024

Summary of Changes

Joomla has been improving its SEO performance constantly and one issue which is still open is, that you can reach the same page via different URLs. This means that you can reach the same article both via the wanted URL, but also via the /component/content/article/<id> URL or even via index.php?option=com_content&view=article&catid=<catid>&id=<id>.

This PR adds a new feature which redirects URLs with query parameters to their SEF variant. The router parses the URL and if the original URL contained query parameters, it tries to create a new URL from the information it parsed and if that new URL does not contain any query parameters anymore, it does a redirect to that URL. This will remove a lot of the double URLs for one content item. This only happens for GET requests.

It should be noted, that this does NOT remove every case of duplicate content. For example additional URL parameters are still kept.

I'd like to thank ithelps Digital for sponsoring this feature.

Testing Instructions

  1. Apply the patch
  2. Use some content to test this with, for example the testing sample data.
  3. Go to /park-blog/first-blog-post in your site when you use the testing sample data
  4. Add a ?id=18 to the URL and see that you actually get the "Second Blog Post" displayed instead of the first one.
  5. Enable the option in the SEF plugin.
  6. Reload the frontend page and see that you are redirected to /park-blog/second-blog-post.

Link to documentations

Please select:

@Hackwar Hackwar added Feature PBF Pizza, Bugs and Fun labels Feb 21, 2024
@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators PR-5.1-dev labels Feb 21, 2024
@bembelimen
Copy link
Contributor

I see what you want to achieve here, but:

  • how can a new feature not require documentation (especially such a critical?)
  • the whole feature sounds like it's solved when we implement canonical tags

@Hackwar
Copy link
Member Author

Hackwar commented Feb 22, 2024

Sorry about the documentation. It was late yesterday and I will create documentation for the whole SEF thing in the next 48 hours.

Regarding the canonical tag I would disagree. To me, the canonical tag is just a bandaid to get around using the right URL and thus using the right URL in the output is the first step (which we do in Joomla anyway). The second step would then be to redirect wrong URLs to the right ones instead of keeping them and slapping a canonical on there.

@ceford
Copy link
Contributor

ceford commented Feb 23, 2024

I have tested this item ✅ successfully on 6ae36cb


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

1 similar comment
@nielsnuebel
Copy link
Contributor

I have tested this item ✅ successfully on 6ae36cb


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

@richard67
Copy link
Member

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 24, 2024
@Hackwar
Copy link
Member Author

Hackwar commented Feb 24, 2024

Link to documentation has been added.

@SniperSister
Copy link
Contributor

I've played around with this PR using the "testing" dataset in Joomla 5.1.x.

I've run into an edge case:

  • The testing dataset has an article that isn't accessible via it's own menu item but only via a category list, it's article ID 1, "
    Administrator Components": index.php/content-component/article-category-list/extensions/components/administrator-components
  • If I now open the "Archive Module" menu item (/index.php/content-component/archive-module) and add an extra query parameter to override the article id with the ID 1 (/index.php/content-component/archive-module?id=1) I'm receiving a redirect to this URL: /index.php/content-component/archive-module?view=article&id=1, whereas my expectation would have been a redirect to the category list URL mentioned above.

I'm aware that this is not quirk of the current PR but of the router in general. However, the current PR might increase the effects.

That's why I'm asking myself if we should limit the redirection to "clean" URLs without any leftover query parameters.

Thoughts? @Hackwar

@Hackwar
Copy link
Member Author

Hackwar commented Feb 24, 2024

I agree, this sounds good. I'll add this to the PR.

@Hackwar
Copy link
Member Author

Hackwar commented Feb 24, 2024

I encountered additional issues and will convert this back to draft first.

@Hackwar Hackwar marked this pull request as draft February 24, 2024 12:17
@richard67 richard67 removed RTC This Pull Request is Ready To Commit Documentation Required labels Feb 24, 2024
@richard67
Copy link
Member

Back to pending.


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

@joeforjoomla
Copy link
Contributor

What about a generic fetch/xhr request to index.php?option=com_xxx&...
Do you mean that with this option enabled it will no longer be possible to perform a GET request to a raw Joomla URL?
This would be too much generic.

@SniperSister
Copy link
Contributor

What about a generic fetch/xhr request to index.php?option=com_xxx&...

Fetch / XHR requests do follow redirects automatically.

@miguelvazquez
Copy link

it works, perfect


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

….1-router-sef

# Conflicts:
#	administrator/language/en-GB/plg_system_sef.ini
#	plugins/system/sef/sef.xml
#	plugins/system/sef/src/Extension/Sef.php
@SniperSister
Copy link
Contributor

I have tested this item ✅ successfully on 33d1153

I've tested the following scenarios:

  • local installation for test dataset, crawled whole site before applying the patch and enabling the feature - after applying the patch, i recrawled the site and got no 404s
  • I've tried various non-sef URL pattern (index.php?Itemid=..., index.php?option=com_users&view=reset&Itemid=...) and got the expected result
  • I've tested the example provided in the test instructions
    This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42854.

@Hackwar Hackwar marked this pull request as ready for review March 13, 2024 21:02
@Hackwar Hackwar changed the title [5.1] SEF: Enforcing correct SEF URL [5.2] SEF: Enforcing correct SEF URL Mar 13, 2024
@Hackwar Hackwar changed the base branch from 5.1-dev to 5.2-dev March 13, 2024 21:02
plugins/system/sef/sef.xml Outdated Show resolved Hide resolved
Co-authored-by: Quy <quy@nomonkeybiz.com>
@joomla-cms-bot joomla-cms-bot removed the Language Change This is for Translators label May 6, 2024
@joomla-cms-bot joomla-cms-bot added the Language Change This is for Translators label May 6, 2024
@joomla-cms-bot joomla-cms-bot removed the Language Change This is for Translators label May 11, 2024
@Hackwar
Copy link
Member Author

Hackwar commented May 11, 2024

I refactored the PR to use the new option from #43432 to reduce the number of options we add here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature PBF Pizza, Bugs and Fun PR-5.2-dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants