[MAGNOLIA-8378] Configurable way to end links with slash Created: 11/Apr/22  Updated: 24/Oct/23

Status: Open
Project: Magnolia
Component/s: core
Affects Version/s: 6.2.17
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Richard Gange Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: seo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relation
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Documentation update required:
Yes
Team: Nucleus

 Description   

Frequently we are getting requests about how to generate links with a slash at the end rather than dot html or nothing at all. We need a configurable way to tell the system (LinkUtil) to generate links with a slash at the end. Mostly for SEO purposes.

The new configuration might make sense here /server/rendering/linkManagement/transformers.

endLinksWithSlash = true

Probably it would need to override any value that is configured here /server@defaultExtension

Another option would be to allow '/' to be an acceptable value for /server@defaultExtension

Notes
One of the issues we face is there is no easy way to override LinkUtil. It's not in the server config nor is it defined in a module descriptor.

The system is already capable of handling the ending slash. All of these links work:

Workaround
First, you will need remove the html value of /server/defaultExtension property (but this leaves the "." at the end of generated links).
So second, to be able to use just "/" as default extension you have to modify info.magnolia.cms.beans.config.URI2RepositoryMapping class and its getURI method. Like this:

    public String getURI(Link uuidLink){
        String uri = uuidLink.getHandle();
        if (StringUtils.isNotEmpty(this.handlePrefix)) {
            uri = StringUtils.removeStart(uri, this.handlePrefix);
        }
        if (StringUtils.isNotEmpty(this.URIPrefix)) {
            uri = this.URIPrefix + "/" + uri;
        }

        String nodeDataName = uuidLink.getNodeDataName();
        String fileName = uuidLink.getFileName();
        String extension = uuidLink.getExtension();

        if(StringUtils.isNotEmpty(nodeDataName)){
            uri += "/" + nodeDataName;
        }
        if(StringUtils.isNotEmpty(fileName)){
            uri += "/" + fileName;
        }
        if(StringUtils.isNotEmpty(uri) && StringUtils.isNotEmpty(extension) && !StringUtils.endsWith(uri, "/")){
-           uri += "." + extension ;
+           uri += extension ;
        }

        return cleanHandle(uri);
    }

With that change in magnolia-core you will no longer get hardcoded "." before extension and (also google sitemap module) will use this new format with default configuration.


Generated at Mon Feb 12 04:32:12 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.