-1

I have the below content structure.

  • site

      - de
    
               - category1
    
                         - 2001
    
                               - quarter1
    
                                    - blog_about_vegan
    
                                    - blog_about_flowers
    
                               - quarter2
    
                                    - blog_about_something
    
                         - 2002
    
                               - quarter1
    
                                    - blog_about_vegan
    
                                    - blog_about_flowers
    
                               - quarter2
    
                                    - blog_about_something
    

I want customers to use shorthand urls. For instance; Customer should get blog_about_vegan when he tries the following url : https://www.somedomain.com/site/de/category1/blog_about_vegan. He should not be worried about the year and quarter as they are just meant for categorization.

I have configured sling mappings in /etc/map to remap the url to search for content in /content. But i am not able to figure out how can I ask sling to look into all year and quarter folders for a particular category to find this article.

I am looking for something like a dynamic internal redirect with nested search capability. could you please advice

Jithin Kumar
  • 49
  • 1
  • 9
  • if you dont include the year and quarter, then how will your user be able to go to /de/category1/2001/quarter1/blog_about_vegan AND /de/category1/2002/quarter1/blog_about_vegan ? because they are different. I think you should keep the year and quarter to guarantee uniqueness unless you implement a firs-match strategy.. – Ahmed Musallam Sep 06 '19 at 02:33
  • It looks like it is better to handle the URL rewriting/transformation at the dispatcher/Apache level. – ronnyfm Nov 05 '19 at 12:08

1 Answers1

3

The Sling RequestResolver will NOT do any searching or querying. So you need to manipulate your URL (in the web-server), that it matches with a Servlet of you. Then your Servlet will query/resolve the remaining part of the URL and forward the rendering to Sling again.

I recommend to use the Sling-Suffix for category and article. So the URL in AEM would be http://localhost:4502/content/site/de.article-search.html/category1/blog_about_vegan. This is easily done in the web server (e.g. mod_rewrite). Then you register a servlet for the 'de'-resourceType and selector 'article-search'.

Then with request.getRequestPathInfo().getSuffix() you can find the article. If you find the page/resource, with request.getRequestDispatcher(...).forward(...) you can let Sling do the rendering.

Alexander Berndt
  • 1,628
  • 9
  • 17
  • Thanks for the Reply. The better approach is to use a servlet or to extend Resource resolver and add custom logic? – Jithin Kumar Sep 02 '19 at 11:50
  • 1
    Please do a Servlet. The request resolving is already way too over-engineered and the core of Sling. Don’t mess around with this. There is a good chance to fail. – Alexander Berndt Sep 02 '19 at 11:54