Forum Discussion

duahire's avatar
duahire
Helper
2 years ago

How to redirect to Custom page from Page-initialization-script

Hello Team,

 

I have to redirect to one my custom page from Permission denied page(which is throwing 400 error).

How to do this from Page-initialization-script

  • Correct me if I'm wrong, but I had to deal with this before. The problem is: Error Requests never arrive at the page init code, they are generated and handled earlier and thus we can't handle them in page init!

    You are also out of luck with the custom redirect Admin Feature (go to /t5/bizapps/bizappspage/tab/community%3Aadmin%3Asystem%3Aseo%3Aseo-redirects-settings in your community for that), at least if you want to redirect an arbitrary (non /t5/...) URL to somewhere else, e.g. /some_inexistent_page as a source URL will not be accepted...

    Depending on how users "arrive" at the error page, e.g. through a link on your community, you might be able to intercept the link click with JavaScript and redirect from there, if that is not the case you might want to file a support case and ask if they can add that custom redirect directly to the Server config (Apache .htaccess or something)...but in your case it might be even trickier, as you don't want ALL users to be redirected, but just the ones without permission... Maybe a bit more details on what exactly you are dealing with would help craft a solution?

  • Hi duahire 

    Please try this in Page Init - 

    <#if http.request.url == "PERMISSION DENIED PAGE URL" >
      ${http.response.setRedirectUrl('CUSTOM PAGE URL')}
    </#if>