Does CQ provide a way to change or strip the suffix from the current URL but preserve the query params? | Community
Skip to main content
LinearGradient
Level 6
October 16, 2015
Solved

Does CQ provide a way to change or strip the suffix from the current URL but preserve the query params?

  • October 16, 2015
  • 3 replies
  • 1915 views

Hi,

I am looking for a way to transform the current request URL into one with a different suffix and preserve everything else.

Does CQ (or Sling) has an API for doing this? Or do I have to do it manually, maybe with some help from slingRequest.getRequestPathInfo()?

Thanks,
Behrang

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

You can get the suffix, selectors from the URL (https://sling.apache.org/apidocs/sling5/org/apache/sling/api/request/RequestPathInfo.html) but there is nothing to replace it. Hope you are already doing the same !

3 replies

Lokesh_Shivalingaiah
Level 10
October 16, 2015

I am not aware of any such methods in APIs. you should handle it manually.

but can you explain a usecase here ?

LinearGradient
Level 6
October 16, 2015

We have a requirement to implement pagination and to use path variables rather than query parameters (e.g. /books/1, /books/2, etc. rather than /books?page=1, /books?page=2, etc.)

In this case, /1, /2, etc. are resolved as suffixes by CQ. So I need to extract the suffix and replace it. At the moment I am doing it manually, but it would be nice if there was a way to transform the current URL into another one with selector, suffix, etc. replaced with different values.

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
Level 10
October 16, 2015

You can get the suffix, selectors from the URL (https://sling.apache.org/apidocs/sling5/org/apache/sling/api/request/RequestPathInfo.html) but there is nothing to replace it. Hope you are already doing the same !