Forum Discussion

jeffshurtliff's avatar
4 years ago

Can't get redirects to work in page initialization script to fix JX migration issue

We recently migrated to Khoros from JX (aka Jive-x) and have found that most (if not all) external links within messages are broken because JX routed external links through a redirect mechanism via URL manipulation like this:  https://community.example.com/external-link.jspa?url=https:%2F%2Fgoogle.com 

Unfortunately the URLs are all broken and route to the Page Not Found page.

I was hoping I would be able to use the Page Initialization Script to redirect the the URLs to the correct destinations with the FreeMarker code below, but for some reason the code seems to have no effect at all.  (I'm not even seeing anything in the Toolbox.)

<#-- Redirect URLs leveraging the Jive external link redirect -->
<#if (http.request.url)?contains('external-link.jspa')>
  <#assign jiveExternalUrl = (http.request.url)?split('external-link.jspa?url=')[1] />
  <#assign jiveExternalUrl = jiveExternalUrl?replace('%2F', '/') />
  <#assign jiveExternalUrl = jiveExternalUrl?replace('%3A', ':') />
  <#assign jiveExternalUrl = jiveExternalUrl?replace('http:', 'https:') />
  ${http.response.setRedirectUrl(jiveExternalUrl)}
</#if>

Any ideas what I'm doing wrong here, or is there a different way that I should be going about what I'm trying to do?

Thanks!!

  • Hi jeffshurtliff ,

    What you're running into is that there is a variety of core logic that executes prior to Page Initialization Script, and one of those is the 404 handler. So you unfortunately won't be able to preempt non-existent community pages from within Page Initialization Script.

    However, we have encountered this exact scenario in the past and we have a fix that should be able to help. Can you please open a case with Support and ask them to route this to "PSS" and reference this post so they have proper context? 

  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi jeffshurtliff ,

    What you're running into is that there is a variety of core logic that executes prior to Page Initialization Script, and one of those is the 404 handler. So you unfortunately won't be able to preempt non-existent community pages from within Page Initialization Script.

    However, we have encountered this exact scenario in the past and we have a fix that should be able to help. Can you please open a case with Support and ask them to route this to "PSS" and reference this post so they have proper context?