Expand my Community achievements bar.

SOLVED

CQ5 Redirect Issue

Avatar

Level 1

I am having an issue with the redirect functionality in CQ5.

 

Essentially, I can set a redirect in the page properties of any page on my site. However this redirect only seems to work when I navigate to that page through a link. For example starting on the homepage and clicking through to the page in question - then it redirects as I have set in the properties.

However, the redirect does not happen when I navigate to the URL directly in the browser. Does anyone know why this is?

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi there,
As Scott mention. There is a direct and hardcoded way of doing this by different mapping that will handle the requests for a page so you don't even get to that page in the first place. This of course could be a bit annoying if these pages change from time to time and that is something that is up to any authors to decide. Ususally you don't want them to change any mappings in the platform.

As you probably have noted, the usage of the redirect functionality is most sometime handled _outside_ of the page that has this attribute like a navigational list of some kind (think menu bar). This menu then looks at all the pages and if they lack a redirect target, it will create a link to that page, otherwise it will redirect to the other page. 
This however brings us to your problem, without the mappings, there is no way for CQ to know that you are going for a redirect without any mappings done.

One possible solution for this could be, at the page template level, to have a check at the top of your pages that will handle the redirect if the page has a redirect target set.
The following code explains how to do this by a small example:
 

<% String redirectTarget =  properties.get("GET THE REDIRECT PROPERTY FROM THE PAGE HERE", String.class); if(!redirectTarget == null || ... or empty){} response.setStatus(response.SC_MOVED_TEMPORARILY); response.setHeader("Location", redirectTarget); } %> This is just a suggestion and the above code is only an example of what i mean. I hope you get the idea. Good Luck :)


 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

Hi there,
As Scott mention. There is a direct and hardcoded way of doing this by different mapping that will handle the requests for a page so you don't even get to that page in the first place. This of course could be a bit annoying if these pages change from time to time and that is something that is up to any authors to decide. Ususally you don't want them to change any mappings in the platform.

As you probably have noted, the usage of the redirect functionality is most sometime handled _outside_ of the page that has this attribute like a navigational list of some kind (think menu bar). This menu then looks at all the pages and if they lack a redirect target, it will create a link to that page, otherwise it will redirect to the other page. 
This however brings us to your problem, without the mappings, there is no way for CQ to know that you are going for a redirect without any mappings done.

One possible solution for this could be, at the page template level, to have a check at the top of your pages that will handle the redirect if the page has a redirect target set.
The following code explains how to do this by a small example:
 

<% String redirectTarget =  properties.get("GET THE REDIRECT PROPERTY FROM THE PAGE HERE", String.class); if(!redirectTarget == null || ... or empty){} response.setStatus(response.SC_MOVED_TEMPORARILY); response.setHeader("Location", redirectTarget); } %> This is just a suggestion and the above code is only an example of what i mean. I hope you get the idea. Good Luck :)