Search code examples
aemsling

CQ5 response.sendRedirect with dispatcher


I would like to redirect a request to an other page by some condition. In cq5 I can check whether the page I want to redirect the request exists or not. But dispatcher handles only static HTML, so how I can handle redirects to be compatible with dispatcher?

So how can I use response.sendRedirect() with dispatcher?


Solution

  • If I understand correctly, you have a page that sometimes redirects to somewhere else and sometimes simply displays a content. If the page decides to redirect, dispatcher won't cache it. However, if the page displays a content (even once), it will be cached and from this moment all users will get the cached resource.

    You can do 2 things:

    • move the redirection logic to Javascript, so it'll executed even if the page is cached,
    • add a cache rule to dispatcher configuration preventing this concrete path from being cached.