Expand my Community achievements bar.

SOLVED

URL rewrite not happening with request forwarding

Avatar

Level 2

Hi All,

 

Need some help with below scenario

We have a scenario where we are doing some internal forwards as below:

Example:

1. User hits /content/site/language/mypage.html

2. Based on some rules we are forwarding the request to /content/site/language/page

3. User still sees /content/site/language/mypage.html in browser url but the content is coming from 

/content/site/language/page

 

request.getRequestDispatcher("/content/site/language/page").forward(request,response);
The request is being forwarded on /content/site/language/page however the link transformer is not getting called and hence all the links on output page are not rewritten(shortened).
 
Expected behavior is all links should be shortened in case of forwarding the request.
1 Accepted Solution

Avatar

Correct answer by
Level 2

The correct solution is as below:

Found the issue. The request.getRequestDispatcher("/content/site/language/page").forward(request,response) does not invoke sling pipeline hence sling rewriter was not getting called.

 

We can use SlingRequestProcessor to get the response and this calls sling pipeline.

View solution in original post

6 Replies

Avatar

Level 2

Hi arunpatidar,

Found the issue. The request.getRequestDispatcher("/content/site/language/page").forward(request,response) does not invoke sling pipeline hence sling rewriter was not getting called.

 

We can use SlingRequestProcessor to get the response and this calls sling pipeline.

Avatar

Community Advisor

If you want the redirect url to be updated in url as well then you should be using sendRedirect() method of the servlet. Read this article to know more https://www.javatpoint.com/sendRedirect()-method#:~:text=Difference%20between%20forward()%20and%20se....

Avatar

Level 2

Hi  DPrakashRaj,

 

The browser url should not be changed. This is working correctly. The urls present in the page content should be rewritten according to resolver rules.

Example

1.User hits /content/site/page1.html

2. Internally forward request to /content/site/page2.html

3.Browser still shows /content/site/page1.html however the content is coming from /content/site/page2.html

4.All the links in /content/site/page2.html should be rewritten.

 

Avatar

Administrator

@mmohta11 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

 



Kautuk Sahni

Avatar

Correct answer by
Level 2

The correct solution is as below:

Found the issue. The request.getRequestDispatcher("/content/site/language/page").forward(request,response) does not invoke sling pipeline hence sling rewriter was not getting called.

 

We can use SlingRequestProcessor to get the response and this calls sling pipeline.