Forum Discussion
Thanks, PaoloT ! That did work. I'm stuck on one thing though. I think it's erroring out when there is no http.request.referrer.
The below code runs on page initialization on the page: /t5/forums/postpage/board-id/features.
When I go from /t5/Feature-Requests/idb-p/features and click new post, I go to /t5/forums/postpage/board-id/features, correctly it does not load, and I am successfully redirected via this redirect:
${http.response.setRedirectUrl("/t5/custom/page/page-id/AcceptIdeasTerms?postlocation=/t5/forums/postpage/board-id/" + postTo)}
However, when I paste the URL of the post page in the browse (/t5/forums/postpage/board-id/features) , I am not redirected, and the post page loads.
According to the logic in the code below, I think the user should be directed to /t5/Feature-Requests/idb-p/features if http.request.referrer does not exist, or if it exists, but does bnot contain ("/idb-p/").
My guess is that it's erroring out, and therefore not redirecting, because of the handling of an unexpected value for prevUrl (http.request.referrer). Any thoughts on how this might be resolved? Again, when prevUrl does contain "/idb-p/" then that part of the code works great.
<#if terms_accepted != 'true'>
<#assign prevUrl = http.request.referrer />
<#if prevUrl??>
<#if prevUrl?contains("/idb-p/")>
<#assign urlSections = prevUrl?split("/") />
<#assign postTo = urlSections[urlSections?size - 1] />
${http.response.setRedirectUrl("/t5/custom/page/page-id/AcceptIdeasTerms?postlocation=/t5/forums/postpage/board-id/" + postTo)}
<#else>
${http.response.setRedirectUrl("/t5/Feature-Requests/idb-p/features")}
</#if>
<#else>
${http.response.setRedirectUrl("/t5/Feature-Requests/idb-p/features")}
</#if>
</#if>
Ok! Answered my own question. I needed to test if http.request.referrer exists before assigning its value to a variable. Here's the updated code:
<#if terms_accepted != 'true'>
<#if http.request.referrer?? >
<#assign prevUrl = http.request.referrer />
<#if prevUrl?contains("/idb-p/")>
<#assign urlSections = prevUrl?split("/") />
<#assign postTo = urlSections[urlSections?size - 1] />
${http.response.setRedirectUrl("/t5/custom/page/page-id/AcceptIdeasTerms?postlocation=/t5/forums/postpage/board-id/" + postTo)}
<#else>
${http.response.setRedirectUrl("/t5/Feature-Requests/idb-p/features")}
</#if>
<#else>
${http.response.setRedirectUrl("/t5/Feature-Requests/idb-p/features")}
</#if>
</#if>
Related Content
- 9 years ago
- 2 years ago
- 2 years ago
- 2 years ago