Expand my Community achievements bar.

AEM Redirect not working expected on the publish.

Avatar

Level 7

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

6 Replies

Avatar

Community Advisor

Hi @kevingtan 

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

Avatar

Level 7

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>

 

 

Avatar

Community Advisor

Hi @kevingtan 

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

Avatar

Level 7

It's nothing special about authoring the url, using the same field type, and selecting the path from the "pathfield". This works fine on both author and dispatcher, the author will go to https://myauthor.com/content/proj/about.html, the dispatcher will go to https://mysite.com/about/about-me.html, where is redirected from about.html. 

 

We have a base.jsp file, on top of it we leverage SlingHttpServletResponse, such as

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

// -- do some parsing redirecPath to produce a url

response.sendRedirect(url);

 

After taking care of this, we start the <html> page.

This is not the point, my question is that why the touchUI doesn't work the same way. I try to add something before wcm/components/page/v2/page.html, it shows the redirect page on the author because there is an OOTB redirect.html taking care of it. the redirect.html only takes care the author, but not the publish site. I try to implement the custom module as shown in base.jsp, it fails to react.

 

best,

-kt

 

Avatar

Level 7

I found the difference between our classic and the current touchUI. The redirect field names are different. One is "cq:redirectTarget", the other one is "redirectTarget". The name was changed during the code migration.

Avatar

Administrator

@kevingtan 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