Hello!
We are migrating our client from 6.4 to 6.5 and also converting static templates to dynamic templates. We are using v3 of the Page component provided by core wcm components. With this page core component, we can set the redirect target in the page properties under advance tab. It works fine but we have a requirement to change the redirect code to 301 (Moved Permanently). How do we go about this implementing it?
The search for 301 redirects in the experience league community brings several results, but the solutions they provide seem to be more fitted for foundation page component (not the core component, I might be wrong though).
Any help/pointes you can provide will be greatly appreciated!
Thanks,
SkmAtl
Solved! Go to Solution.
Views
Replies
Total Likes
hi @skmAem ,
Could you please try below approach
if (properties.containsKey("redirectTarget")) {
String redirectTarget = properties.get("redirectTarget", String.class);
response.setStatus(Integer.parseInt(properties.get("redirectStatusCode", "301")));
response.setHeader("Location", redirectTarget);
} else {
// Render your page normally
}
This code checks for the "redirectStatusCode" property on the current page and sets the HTTP response code to 301 if it exists. If the "redirectTarget" property exists, it sets the "Location" header on the HTTP response to the value of that property.
HI @skmAem
Please check this thread- https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/provide-301-redirect-in-ae...
Thanks
Dipti
hi @skmAem ,
Could you please try below approach
if (properties.containsKey("redirectTarget")) {
String redirectTarget = properties.get("redirectTarget", String.class);
response.setStatus(Integer.parseInt(properties.get("redirectStatusCode", "301")));
response.setHeader("Location", redirectTarget);
} else {
// Render your page normally
}
This code checks for the "redirectStatusCode" property on the current page and sets the HTTP response code to 301 if it exists. If the "redirectTarget" property exists, it sets the "Location" header on the HTTP response to the value of that property.
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies