留言板

Liferay 7 - Custom "not found (404 error)" page

Marc Roger,修改在6 年前。

Liferay 7 - Custom "not found (404 error)" page

New Member 发布: 1 加入日期: 17-5-11 最近的帖子
Hi,

I'm developing with Liferay 7 and I would like to create a custom page for the 404 error.
In Liferay 6.2 this is solved by adding this line in the portal-ext.properties file:
layout.friendly.url.page.not.found=/custom-error-page

This property doesn't works on Liferay 7. How should I configure this redirect on my portal?

Thanks in advance.
thumbnail
Yannis Sinadinos,修改在6 年前。

RE: Liferay 7 - Custom "not found (404 error)" page

Junior Member 帖子: 39 加入日期: 17-3-20 最近的帖子
Hi,
I have the same issue and the "layout.friendly.url.page.not.found=/custom-error-page" doesn't work in Liferay 7 GA4.
Did you find any solution?

Thank you,
Yannis
thumbnail
Mayur Mulani,修改在5 年前。

RE: Liferay 7 - Custom "not found (404 error)" page

New Member 帖子: 3 加入日期: 17-3-2 最近的帖子
Hi Marc,

It can be resolved by multiple ways.

Option 1

layout.friendly.url.page.not.found=/web/guest/page-not-found.

include mentioned above property in portal-ext.properties file. Create one public page page-not-found and make your custom design for this page .

Option 2 : 

layout.friendly.url.page.not.found=/html/portal/error/404-page-not-found.jsp

include mentioned above propery in portal-ext.properties file. Create one jsp file on mentioned path.  Make some rewrite rule in that jsp file.  By making your own custom redirect logic you can redirect page as you want.

<%@ page import="com.liferay.portal.kernel.util.PortalUtil" %>

<%! private static final String PAGE_404_URL = "/page-404-not-found"; %>

<c:import url='<%= PortalUtil.getPortalURL(request) + PAGE_404_URL%>'/>​​​​​​​


Option 3 :

Override code.jsp file (Create core jsp hook). In liferay dxp error pages being handled by code.jsp which is residing under ROOT/errors/code.jsp. This logic you can find it in web.xml (ROOT/webapps/WEB-INF/web.xml)

<error-page>
        <error-code>404</error-code>
        <location>/errors/code.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/errors/code.jsp</location>
    </error-page>


So make custom jsp bag hook to override code.jsp file where you can handle 403, 500  and rest of the error pages as well. you can put your own design or redirect page from this jsp file according to your requirement.


Note :  Option 1 wont work for all the scenarios. It will be failed for some of the scenarios.

Thanks,
Mayur Mulani