core components page 301 redirect | Community
Skip to main content
Level 3
May 2, 2023
Solved

core components page 301 redirect

  • May 2, 2023
  • 2 replies
  • 786 views

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 

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 MayurSatav

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.

2 replies

Dipti_Chauhan
Community Advisor
Community Advisor
May 3, 2023
MayurSatav
Community Advisor and Adobe Champion
MayurSatavCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
May 3, 2023

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.