Search code examples
aemsling

Map full content path into a domain name and a subpath


This blog presents a sample Sling Mappings configuration that maps paths like /content/geometrixx/en/... into URL http://geometrixx.com/.... Is it possible to prepare a similar configuration that adds an additional path part just after the domain? I'd like to map:

/content/geometrixx/en/...

into

http://mycompany.com/geometrixx/...

Solution

  • It's possible to nest one sling:Mapping node into another and if you don't have the sling:match property, the nested node name will be treated as a subpath. Sample configuration may look like this:

    {
        "jcr:primaryType": "sling:OrderedFolder",
        "mycompany_com_geometrixx": {
            "jcr:primaryType": "sling:Mapping",
            "sling:match": "mycompany.com/geometrixx$",
            "sling:internalRedirect": ["/content/geometrixx/en.html"],
        },
        "mycompany.com": {
            "jcr:primaryType": "sling:Mapping",
            "geometrixx": {
                "jcr:primaryType": "sling:Mapping",
                "sling:internalRedirect": "/content/geometrixx/en"
            }
        }
    }
    

    The first mapping (mycompany_com_geometrixx) is responsible for mapping this exact path:

    http://mycompany.com/geometrixx
    

    into the en.html webpage, so the user doesn't have to provide .html extension at the end of it. The second mapping mycompany.com contains nested geometrixx mapping to configure the following URL pattern: http://mycompany.com/geometrixx/...