How to implement pretty URLs in AEM? (URL parameters but without using ?parameter-here=xxx) | Community
Skip to main content
jayv25585659
Level 8
Apr 18, 2018 1:52 AM UTC

How to implement pretty URLs in AEM? (URL parameters but without using ?parameter-here=xxx)

I want to create a URL like this.

www.myhost.com/my-page/john.smith

my-page is an AEM page while john.smith is a parameter to the page. It's really like

www.myhost.com/my-page?name=john.smith

but the first URL that looks nicer. Is this something AEM can do (like config changes) or perhaps this is an Apache rewrite rules? Perhaps combination of both?

Sample please?

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

6 replies

anjali_biddanda
Level 4
May 7, 2018 2:10 AM UTC

You'll need to use a sling servlet with a selector. Your selectors will be firstname, lastname. Your sling servlet annotation will look like this:
@SlingServlet(resourceTypes = "myBrand/components/pages/myPeoplePageType", selectors =

{firstname, lastname}

, extensions = "html”, methods=”GET”)

Your URL below:
http://www.myhost.com/people.firstname.lastname
will invoke your servlet and pass current page path along with other parameters. Servlet would be resolved through selectors & resource type.

Then you will need a dispatcher rewrite rule that will take /my-page/john.smith and transform it into /my-page.john.smith. You can test your /my-page.john.smith on your author instance. But for the pretty URL, you'll need your dispatcher set up. Or you might be able to do this URL mapping (under /etc/maps) as a regexmap (https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html#mapping-entry-specification), in which case, you can test it in your author.

https://forums.adobe.com/thread/2325530
http://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/
https://helpx.adobe.com/experience-manager/6-2/managing/using/seo-and-url-management.html (Look at sections - "Using Sling Selectors" and "Sling servlets (one level down)")

Translate
Hemant_arora
Level 8
Apr 24, 2018 5:41 AM UTC

Yes it can be tested locally. no publish no dispatcher required

Translate
Hemant_arora
Level 8
Apr 18, 2018 5:54 AM UTC

You can add a sling mapping for making your pages load with URL 1

You can perform a regular expression matching which matches all url with extension .smith and redirect internally in AEM to /content/my-page/john

Refer to https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html#mapping-entry-specification

Translate
edubey
Level 10
Apr 18, 2018 4:32 AM UTC

Your first URL goes towards selector implementation in AEM,


Look at the complete guide here https://helpx.adobe.com/experience-manager/6-2/managing/using/seo-and-url-management.html

Translate
jayv25585659
Level 8
Apr 18, 2018 5:35 AM UTC

thanks! I searched but your link didn't come up.

Translate