AEM Redirect not working expected on the publish. | Community
Skip to main content
Level 5
January 14, 2025

AEM Redirect not working expected on the publish.

  • January 14, 2025
  • 2 replies
  • 1175 views

Hi team,

 

I need help for the redirect issue.

All my contents are under /content/proj. The dispatcher is under /var/cache/content/proj, all rewrites are rewritten to /var/cache/content/proj. So an article in author /content/proj/news/xyz.html will be https://mysite.com/news/xyz.html. This works under the dispatcher rewrite rules. 

 

I have a page /content/proj/about/about-me.html, it works fine. Now I set up its parent /content/proj/about, it has a redirect as a "

granite/ui/components/coral/foundation/form/pathfield", the value is /content/proj/about/about-me.html, the name for the field is "cq:redirectTarget". On the author it just shows the title of the /content/proj/about/about-me.html, but the front-end just being redirected to https://mysite.com/content/proj/about/about-me.html, in turn, resulted a 404 page. Since this is a pathfield field, I don't want to just enter /about/about-me.html for the redirect, rather, pick a page from the AEM built-in popup/popdown path field. I try to implement a model to redirect it, such as

 

String redirectPath = properties.get("cq:redirectTarget", "");

if(redirectPath != null && !redirectPath.equals(""))

{

     response.sendRedirect(redirectPath);

}

 

It's weird that the author shows the correct redirectPath, but not the publisher because the page is always located at 404. In other words, the model always kicks in after the redirect on the publish server. Is there a config under /system/console/configMgr doing this?

 

Appreciate your help!

 

-kt

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

2 replies

arunpatidar
Community Advisor
Community Advisor
January 15, 2025

Hi @kevin_gta 

You need an additional redirect rule at apache to redirect anything from /content/proj to /

then  https://mysite.com/content/proj/about/about-me.html will be redirected to  https://mysite.com/about/about-me.html

Arun Patidar
Kevin_GTaAuthor
Level 5
January 15, 2025

Hi @arunpatidar 

 

That's not exactly what I want.

That's not exactly what I want. I want anything under https://mysite.com/content/proj/target.html to get a 404 page except target.html has a redirect because there is no /content/proj/content/proj/target.html in the cache server.

 

https://mysite.com/target.html maps to /var/cache/content/proj/target.html

https://mysite.com/content/proj/target.html 404

https://mysite.com/about redirected to https://mysite.com/about/about-me.html

 

In our old classic site, it was working because we had a jsp module to handle that. I thought sightly can do the same job but the sightly module kicks in too late.

 

Jsp:

<%

//-- does the redirect if properties.get("redirectTarget") exists, it works.

%>

<html>

</html>

 

Sightly

<!--/*

// -- does the redirect if properties.get("cq:redirectTarget") exists, but never gets into this section because the page is redirected to /content/proj/somewhere.html, which is resulted a 404.

*/-->

<html>

</html>

 

 

arunpatidar
Community Advisor
Community Advisor
January 15, 2025

Hi @kevin_gta 

How did you authored the redirect url? From page properties or do you have custom component which takes care of redirect? you may try using sling filters?

Arun Patidar
kautuk_sahni
Community Manager
Community Manager
January 27, 2025

@kevin_gta Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni