URL rewrite not happening with request forwarding | Community
Skip to main content
Level 2
October 13, 2023
Solved

URL rewrite not happening with request forwarding

  • October 13, 2023
  • 3 replies
  • 1247 views

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.
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 mmohta11

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.

3 replies

arunpatidar
Community Advisor
Community Advisor
October 13, 2023

Can you check if you have restriction based on path?

try with global pipeline

https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html 

Arun Patidar
mmohta11Author
Level 2
October 16, 2023

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.

DPrakashRaj
Community Advisor
Community Advisor
October 16, 2023

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%20sendRedirect()%20method&text=The%20forward()%20method%20works,response%20objects%20to%20another%20servlet.

mmohta11Author
Level 2
October 16, 2023

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.

 

kautuk_sahni
Community Manager
Community Manager
October 16, 2023

@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
mmohta11AuthorAccepted solution
Level 2
October 16, 2023

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.