Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Redirecting to custom 404 error pages Phoenix Zerin November 1, 2011 11:45 AM
RE: Redirecting to custom 404 error pages Jelmer Kuperus November 1, 2011 12:45 PM
RE: Redirecting to custom 404 error pages David García González January 18, 2012 8:19 AM
RE: Redirecting to custom 404 error pages Jelmer Kuperus January 21, 2012 11:13 AM
RE: Redirecting to custom 404 error pages David García González January 23, 2012 2:13 AM
RE: Redirecting to custom 404 error pages Jelmer Kuperus January 23, 2012 2:26 AM
RE: Redirecting to custom 404 error pages David García González January 23, 2012 9:07 AM
RE: Redirecting to custom 404 error pages Chris Becker February 1, 2012 12:31 PM
RE: Redirecting to custom 404 error pages Paolo Pilitti February 3, 2012 9:35 AM
RE: Redirecting to custom 404 error pages Paolo Pilitti February 6, 2012 8:36 AM
RE: Redirecting to custom 404 error pages Thiago Leão Moreira June 27, 2012 10:12 AM
RE: Redirecting to custom 404 error pages Achmed Tyrannus Albab July 5, 2013 3:25 AM
RE: Redirecting to custom 404 error pages Harsha Mhaske November 13, 2013 6:29 AM
RE: Redirecting to custom 404 error pages Juha Anttila April 23, 2014 1:26 AM
RE: Redirecting to custom 404 error pages Juha Anttila April 29, 2014 11:31 PM
RE: Redirecting to custom 404 error pages Luis Silva June 25, 2014 3:00 AM
RE: Redirecting to custom 404 error pages Vidmantas Banaitis August 19, 2014 12:36 AM
RE: Redirecting to custom 404 error pages Juha Anttila August 19, 2014 8:02 AM
RE: Redirecting to custom 404 error pages Pavel Fomin January 13, 2015 1:41 PM
RE: Redirecting to custom 404 error pages Matthieu Levesque March 13, 2015 5:34 AM
RE: Redirecting to custom 404 error pages Matthieu Levesque March 30, 2015 8:48 AM
RE: Redirecting to custom 404 error pages Stefan Walter May 7, 2015 12:24 AM
RE: Redirecting to custom 404 error pages Matthieu Levesque July 8, 2015 8:03 AM
RE: Redirecting to custom 404 error pages Niccolò Pasquetto March 29, 2016 4:08 AM
Phoenix Zerin
Redirecting to custom 404 error pages
November 1, 2011 11:45 AM
Answer

Phoenix Zerin

Rank: Junior Member

Posts: 60

Join Date: June 28, 2011

Recent Posts

A site that I am working on requires a custom 404 error page.

I am trying to figure out the best way to accomplish this, but I am running into a wall and cannot figure out how to continue.

I initially tried to override layout.friendly.url.page.not.found in portal.properties via a hook, but that seems to have zero effect; 404s do not get redirected to the URL I specify.

The next thing I tried was to override /html/portal/status.jsp in a hook and modify it like this:

1if( SessionErrors.contains(request, PrincipalException.class.getName()) ) {
2  ...
3} else if (noSuchResourceException) {
4    /** @todo Redirect to 404 page. */
5    response.sendRedirect(themeDisplay.getPortalURL() + "/web/guest/home?error=404");
6} else {
7  ...
8}


However, response.sendRedirect() fails silently; I get no error messages anywhere, and the browser is not redirected.

I have also tried setting the headers manually, e.g.:

1response.addHeader("location", themeDisplay.getPortalURL() + "/web/guest/home?error=404");
2response.setStatus(302);


Same result: silent failure.

Am I going down the right path? How should I implement a redirect (internal or external) on a 404 error?
Jelmer Kuperus
RE: Redirecting to custom 404 error pages
November 1, 2011 12:45 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Yeah i remember having some issues with that as well. The value for layout.friendly.url.page.not.found has to be a file on disk and can't be something like a friendly url. I hacked around it like this :

in my portal-ext.properties

1layout.friendly.url.page.not.found=/errors/404-searchworkings.jsp


in the 404-searchworkings.jsp file

 1<%@ page import="com.liferay.portal.util.PortalUtil" %>
 2<%@ page import="com.liferay.portal.NoSuchLayoutException" %>
 3<%@ page import="com.liferay.portal.service.LayoutLocalServiceUtil" %>
 4<%@ page import="com.liferay.portal.util.WebKeys" %>
 5<%@ page import="com.liferay.portal.model.LayoutSet" %>
 6<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 7<%--
 8    It seems we cannot directly specify a portal page in the layout.friendly.url.page.not.found property
 9    So do a jstl import and fake it
10--%>
11<%! private static final String NOT_FOUND_LAYOUT_FRIENDLY_URL = "/not-found"; %>
12<%
13LayoutSet layoutSet = (LayoutSet)request.getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET);
14
15boolean notFoundPageExists = true;
16try {
17    LayoutLocalServiceUtil.getFriendlyURLLayout(layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
18            NOT_FOUND_LAYOUT_FRIENDLY_URL);
19} catch (NoSuchLayoutException e) {
20    notFoundPageExists = false;
21}
22%>
23<c:if test="<%= notFoundPageExists %>">
24    <c:import url="<%= PortalUtil.getPortalURL(request) + NOT_FOUND_LAYOUT_FRIENDLY_URL + ";jsessionid=" + session.getId() %>"/>
25</c:if>


But note that this only will be used in some cases. I added an improvement in jira a while back to support global 404 error pages but so far it has not been looked at by liferay.
If you too would like to have support for this, please vote for : http://issues.liferay.com/browse/LPS-20325
David García González
RE: Redirecting to custom 404 error pages
January 18, 2012 8:19 AM
Answer

David García González

Rank: Regular Member

Posts: 127

Join Date: July 14, 2009

Recent Posts

Hi everybody!

In liferay 6.0.x is it possible to show a custom 404 page per community?

Thanks!
Jelmer Kuperus
RE: Redirecting to custom 404 error pages
January 21, 2012 11:13 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Well in the example above i show you how you get the layoutSet , from that you can get the group, and based on that you can import a different jsp
David García González
RE: Redirecting to custom 404 error pages
January 23, 2012 2:13 AM
Answer

David García González

Rank: Regular Member

Posts: 127

Join Date: July 14, 2009

Recent Posts

But instead of import a custom jsp I wanted to redirect to a portal page where the editors could edit an article showing a 404 message and show the header and footer of the portal.
Jelmer Kuperus
RE: Redirecting to custom 404 error pages
January 23, 2012 2:26 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

That is basically what i am doing in the example
David García González
RE: Redirecting to custom 404 error pages
January 23, 2012 9:07 AM
Answer

David García González

Rank: Regular Member

Posts: 127

Join Date: July 14, 2009

Recent Posts

jelmer kuperus:
That is basically what i am doing in the example


Yes, this is the code I haven't seen:

1<c:if test="<%= notFoundPageExists %>">
2    <c:import url="<%= PortalUtil.getPortalURL(request) + NOT_FOUND_LAYOUT_FRIENDLY_URL + ";jsessionid=" + session.getId() %>"/>
3</c:if>


Thanks!!!
Chris Becker
RE: Redirecting to custom 404 error pages
February 1, 2012 12:31 PM
Answer

Chris Becker

Rank: Regular Member

Posts: 112

Join Date: June 11, 2010

Recent Posts

Hi Jelmer;

Did you implement your 404-searchworkings.jsp via a hook?

Regards,

--Chris
Paolo Pilitti
RE: Redirecting to custom 404 error pages
February 3, 2012 9:35 AM
Answer

Paolo Pilitti

Rank: Junior Member

Posts: 51

Join Date: April 13, 2011

Recent Posts

Chris Becker:
Hi Jelmer;

Did you implement your 404-searchworkings.jsp via a hook?



im interested in this.
Which are the pages that the hook must overrides?
Paolo Pilitti
RE: Redirecting to custom 404 error pages
February 6, 2012 8:36 AM
Answer

Paolo Pilitti

Rank: Junior Member

Posts: 51

Join Date: April 13, 2011

Recent Posts

i resolved (im in liferay 6.06)

you can override the page portal-web\docroot\errors\404.jsp
putting the overriding page in a hook in
hooks\HookPlugin-hook\docroot\WEB-INF\custom_jsps\errors\404.jsp

and modifing portal-ext.properties
with
layout.show.http.status=true
layout.friendly.url.page.not.found=/html/errors/404.jsp



BUT NOW another problem arise
i have a problem about gzip compression encoding of the page

When i load an non existing url in firefox gives the message
"Errore di codifica del contenuto
La pagina che si sta cercando di visualizzare non può essere mostrata poiché fa uso di una forma di compressione non valida o non supportata.
Contattare il proprietario del sito web per informarlo del problema."


in english something like
"error coding the content, the page cant be showed cause compression is not valid or supported"

while in chrome it gives this error
Errore 330 (net::ERR_CONTENT_DECODING_FAILED): Errore sconosciuto.
""


this error is resolved putting in portal-ext.properties
the line
com.liferay.portal.servlet.filters.gzip.GZipFilter=false


but
Can I so easily disable this option?

how can i resolve the problem in other way?

My objective is that if a user put a wrong url he/she is redirected to the home

how can i do!!!!


After some investigations seems that the gzip compression dowesnt work well for the 404.jsp page
maybe this page is produced in some non conventional way?
Thiago Leão Moreira
RE: Redirecting to custom 404 error pages
June 27, 2012 10:12 AM
Answer

Thiago Leão Moreira

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1433

Join Date: October 10, 2007

Recent Posts

I tried to use the c:import tag but it didn't work, so I changed to c:redirect and... voilá! Worked like a charm.
Achmed Tyrannus Albab
RE: Redirecting to custom 404 error pages
July 5, 2013 3:25 AM
Answer

Achmed Tyrannus Albab

Rank: Regular Member

Posts: 118

Join Date: March 5, 2010

Recent Posts

Jelmer Kuperus:
..
1layout.friendly.url.page.not.found=/errors/404-searchworkings.jsp

...


Hi sorry for ressurecting, a noob question here.
How do i redirect to a file in a different drive?

layout.friendly.url.page.not.found=E:/This/doesnt/work.jsp


Thanks.
Harsha Mhaske
RE: Redirecting to custom 404 error pages
November 13, 2013 6:29 AM
Answer

Harsha Mhaske

Rank: New Member

Posts: 15

Join Date: September 26, 2008

Recent Posts

Hello,

We are facing issues with below type of friendly urls

http://localhost:8080/web/photos-community/photos-community/-/anytthingnotvalid

This takes the user to a blank page, not completely blank but a page with theme and nothing on the main centre page.
Tried layout.friendly.url.page.not.found=/html/errors/404.jsp property but no luck.

Any suggestions?

Regards,
Harsha
Juha Anttila
RE: Redirecting to custom 404 error pages
April 23, 2014 1:26 AM
Answer

Juha Anttila

Rank: New Member

Posts: 14

Join Date: October 19, 2012

Recent Posts

How can you get LayoutSet in Liferay 6.2?

If I iterate through request attributes there's no VIRTUAL_HOST_LAYOUT_SET :

07:24:40,247 INFO (http--0.0.0.0-8080-1) javax.servlet.forward.request_uri
07:24:40,247 INFO (http--0.0.0.0-8080-1) javax.servlet.forward.context_path
07:24:40,247 INFO (http--0.0.0.0-8080-1) javax.servlet.forward.servlet_path
07:24:40,247 INFO (http--0.0.0.0-8080-1) javax.servlet.forward.path_info
07:24:40,248 INFO (http--0.0.0.0-8080-1) COMPANY
07:24:40,248 INFO (http--0.0.0.0-8080-1) com.liferay.portal.kernel.util.CookieKeys
07:24:40,248 INFO (http--0.0.0.0-8080-1) class com.liferay.portal.servlet.filters.cache.CacheFilterSKIP_FILTER
07:24:40,249 INFO (http--0.0.0.0-8080-1) CURRENT_COMPLETE_URL
07:24:40,249 INFO (http--0.0.0.0-8080-1) FRIENDLY_URL
07:24:40,249 INFO (http--0.0.0.0-8080-1) com.liferay.portal.servlet.filters.i18n.I18nFilterSKIP_FILTER
07:24:40,249 INFO (http--0.0.0.0-8080-1) COMPANY_ID
07:24:40,250 INFO (http--0.0.0.0-8080-1) com.liferay.portal.servlet.filters.strip.StripFilterSKIP_FILTER
07:24:40,250 INFO (http--0.0.0.0-8080-1) com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterSECURE_RESPONSE
07:24:40,250 INFO (http--0.0.0.0-8080-1) User-Agent
07:24:40,250 INFO (http--0.0.0.0-8080-1) CURRENT_URL
07:24:40,251 INFO (http--0.0.0.0-8080-1) com.liferay.portal.servlet.filters.gzip.GZipFilterSKIP_FILTER
07:24:40,251 INFO (http--0.0.0.0-8080-1) INVOKER_FILTER_URI

so (LayoutSet)request.getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET) is null.
Juha Anttila
RE: Redirecting to custom 404 error pages
April 29, 2014 11:31 PM
Answer

Juha Anttila

Rank: New Member

Posts: 14

Join Date: October 19, 2012

Recent Posts

Anybody?

Is the hook version correct way to go with Liferay 6.2 custom 404 page?
Luis Silva
RE: Redirecting to custom 404 error pages
June 25, 2014 3:00 AM
Answer

Luis Silva

Rank: Junior Member

Posts: 42

Join Date: April 18, 2013

Recent Posts

Hi,
I'm also using liferay 6.2.
Juha did you solve your issue?
Vidmantas Banaitis
RE: Redirecting to custom 404 error pages
August 19, 2014 12:36 AM
Answer

Vidmantas Banaitis

Rank: New Member

Posts: 1

Join Date: March 24, 2014

Recent Posts

Hi,

You have to have virtual hosts set for your server and site and only then this "VIRTUAL_HOST_LAYOUT_SET" will be set. it will not work with simple localhost.

You may try with computer dns name and ip address for start. is you need more for testing - you can use hosts file on local machine to add more aliases.

Regards,
Vidmantas
Juha Anttila
RE: Redirecting to custom 404 error pages
August 19, 2014 8:02 AM
Answer

Juha Anttila

Rank: New Member

Posts: 14

Join Date: October 19, 2012

Recent Posts

It was a minor issue for us, so we decided to leave it undone. Just before the decision was made tough, I was wondering what it means that in ROOT.war -> WEB-INF -> web.xml there's specified a 404 page :

1<error-page>
2        <error-code>404</error-code>
3        <location>/errors/code.jsp</location>
4</error-page>


so this 404 page can be found in ROOT.war -> errors -> code.jsp but my time was up so I didn't dig deeper.
Pavel Fomin
RE: Redirecting to custom 404 error pages
January 13, 2015 1:41 PM
Answer

Pavel Fomin

Rank: New Member

Posts: 2

Join Date: November 26, 2014

Recent Posts

Setting layout.friendly.url.page.not.found to the friendly url of a page works in Liferay 6.2.
1layout.friendly.url.page.not.found = /web/guest/not-found

where not-found is the friendly url of the page.
Matthieu Levesque
RE: Redirecting to custom 404 error pages
March 13, 2015 5:34 AM
Answer

Matthieu Levesque

Rank: Junior Member

Posts: 62

Join Date: February 13, 2009

Recent Posts

Pavel Fomin:
Setting layout.friendly.url.page.not.found to the friendly url of a page works in Liferay 6.2.
1layout.friendly.url.page.not.found = /web/guest/not-found

where not-found is the friendly url of the page.


Yes it does works if you only have one community/group. On a multi-site instance you want a page not found in each respective sites for the menu and theme...

I've been trying this for a while now, it's just a bit frustrating to see this feature in a stupid simple system like Wordpress. Granted it's in the theme and users wont be able to modify it from the CMS but at least it displays in the same site.
Matthieu Levesque
RE: Redirecting to custom 404 error pages
March 30, 2015 8:48 AM
Answer

Matthieu Levesque

Rank: Junior Member

Posts: 62

Join Date: February 13, 2009

Recent Posts

Here's what we ended up with. We wanted to customize the 404 by sites/communities, so we have built a hook that looks up in the community for a page at the URL /not-found, if it exists we display the not-found page if not, we keep the default implementation of Liferay and use the Status portlet.

Here's the custom 404.jsp:
  1<%@ page import="javax.servlet.http.HttpServletRequest" %>
  2<%@ page import="java.util.regex.Matcher" %>
  3<%@ page import="java.net.URL" %>
  4<%@ page import="java.net.URLConnection" %>
  5<%@ page import="java.util.regex.Pattern" %>
  6<%@ page import="com.liferay.portal.kernel.util.Validator" %>
  7<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
  8<%@ page import="com.liferay.portal.util.Portal" %>
  9<%@ page import="com.liferay.portal.util.PortalUtil" %>
 10<%@ page import="com.liferay.portal.NoSuchLayoutException" %>
 11<%@ page import="com.liferay.portal.service.LayoutLocalServiceUtil" %>
 12<%@ page import="com.liferay.portal.util.WebKeys" %>
 13<%@ page import="com.liferay.portal.model.LayoutSet" %>
 14<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 15<%--
 16    It seems we cannot directly specify a portal page in the layout.friendly.url.page.not.found property
 17    So do a jstl import and fake it
 18--%>
 19<%! private static final String NOT_FOUND_LAYOUT_FRIENDLY_URL = "not-found"; %>
 20<%
 21
 22LayoutSet layoutSetCustom = (LayoutSet)request.getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET);
 23
 24boolean notFoundPageExists = false;
 25
 26HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(request);
 27
 28String url = ParamUtil.getString(request, "previousURL");
 29
 30if (Validator.isNull(url)) {
 31    url = PortalUtil.getCurrentURL(request);
 32}
 33
 34
 35//Valide que ce n'est pas la page not-found
 36Pattern notFoundUrlPat = Pattern.compile(NOT_FOUND_LAYOUT_FRIENDLY_URL+"$");
 37
 38//Get the community URL
 39String communityUrl = "/";
 40Pattern siteUrlPat = Pattern.compile("/(web|group)/[^/]+/");
 41Matcher m = siteUrlPat.matcher(url);
 42
 43if(m.find()) {
 44    communityUrl = m.group();
 45}
 46
 47boolean isSsl = false;
 48String portalUrl = PortalUtil.getPortalURL(request);
 49if(portalUrl.startsWith("https")) {
 50    /*
 51     * Force all inner requests to be non-SSL because of this bug:
 52     *
 53     *  http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6521495
 54     * http://stackoverflow.com/questions/6851461/java-why-does-ssl-handshake-give-could-not-generate-dh-keypair-exception
 55     */
 56    isSsl = true;
 57   
 58    portalUrl = portalUrl.replaceAll("^https", "http");
 59}
 60
 61communityUrl = portalUrl + communityUrl;
 62
 63String redirect = "";
 64
 65if(!notFoundUrlPat.matcher(url).find()) {
 66    String checkUrl = communityUrl+NOT_FOUND_LAYOUT_FRIENDLY_URL;
 67   
 68    //Check if a page not-found exists in the community
 69    try {
 70        URL obj = new URL(checkUrl);
 71        URLConnection conn = obj.openConnection();
 72        String header = conn.getHeaderField(null);
 73        if(header.contains("200")) {
 74            notFoundPageExists=true;
 75            redirect = communityUrl+NOT_FOUND_LAYOUT_FRIENDLY_URL;
 76        }
 77    } catch (Exception e) {}
 78}
 79
 80if(!notFoundPageExists) {
 81    ServletContext servletContext = session.getServletContext();
 82
 83    int status = HttpServletResponse.SC_NOT_FOUND;
 84
 85    redirect = portalUrl +
 86        Portal.PATH_MAIN +
 87        "/portal/status?status="+status+
 88        "&exception=java.lang.NoSuchException&previousURL="+url;
 89}
 90%><c:import var="data" url="<%= redirect %>" charEncoding="UTF-8" /><%
 91String data = (String)pageContext.getAttribute("data");
 92
 93//Change the links back to SSL if the original request was SSLed
 94if(isSsl) {
 95    //Hack the escaping of some of the portal links...
 96    data = data
 97            .replaceAll("&#x3a;", ":")
 98            .replaceAll("&#x2f;", "/")
 99            .replaceAll("&#x2e;", "\\.");
100   
101    String nonSslPortalLink = portalUrl;
102    String sslPortalLink = nonSslPortalLink.replaceAll("^http", "https");
103   
104    data = data.replaceAll(nonSslPortalLink, sslPortalLink);
105}
106%><%=data%>

File path:
<hook home>/docroot/WEB-INF/jsp/html/portal/404.jsp


And we had to modify the status portlet so that it doesn't send an HTTP code other that 200. Without that mod, the c:import fails to import the response and throw a server error (500).
  1<%--
  2/**
  3 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
  4 *
  5 * The contents of this file are subject to the terms of the Liferay Enterprise
  6 * Subscription License ("License"). You may not use this file except in
  7 * compliance with the License. You can obtain a copy of the License by
  8 * contacting Liferay, Inc. See the License for the specific language governing
  9 * permissions and limitations under the License, including but not limited to
 10 * distribution rights of the Software.
 11 *
 12 *
 13 *
 14 */
 15--%>
 16
 17<%@ include file="/html/portal/init.jsp" %>
 18
 19<%
 20int status = ParamUtil.getInteger(request, "status");
 21
 22/*
 23 * We don't want import from the 404 to fail because of an HTTP error
 24 * so we don't set the code.
 25 *
 26if (status > 0) {
 27    response.setStatus(status);
 28}*/
 29
 30String exception = ParamUtil.getString(request, "exception");
 31
 32String url = ParamUtil.getString(request, "previousURL");
 33
 34if (Validator.isNull(url)) {
 35    url = PortalUtil.getCurrentURL(request);
 36}
 37
 38url = themeDisplay.getPortalURL() + url;
 39
 40boolean noSuchResourceException = false;
 41
 42for (String key : SessionErrors.keySet(request)) {
 43    key = key.substring(key.lastIndexOf(StringPool.PERIOD) + 1);
 44
 45    if (key.startsWith("NoSuch") && key.endsWith("Exception")) {
 46        noSuchResourceException = true;
 47    }
 48}
 49
 50if (Validator.isNotNull(exception)) {
 51    exception = exception.substring(exception.lastIndexOf(StringPool.PERIOD) + 1);
 52
 53    if (exception.startsWith("NoSuch") && exception.endsWith("Exception")) {
 54        noSuchResourceException = true;
 55    }
 56}
 57%>
 58
 59<c:choose>
 60    <c:when test="<%= SessionErrors.contains(request, PrincipalException.class.getName()) %>">
 61        <h3 class="portlet-msg-error">
 62            <liferay-ui:message key="forbidden" />
 63        </h3>
 64
 65        <liferay-ui:message key="you-do-not-have-permission-to-access-the-requested-resource" />
 66
 67        <br /><br />
 68
 69        <code><%= HtmlUtil.escape(url) %></code>
 70    </c:when>
 71    <c:when test="<%= SessionErrors.contains(request, PortalException.class.getName()) || SessionErrors.contains(request, SystemException.class.getName()) %>">
 72        <h3 class="portlet-msg-error">
 73            <liferay-ui:message key="internal-server-error" />
 74        </h3>
 75
 76        <liferay-ui:message key="an-error-occurred-while-accessing-the-requested-resource" />
 77
 78        <br /><br />
 79
 80        <code><%= HtmlUtil.escape(url) %></code>
 81    </c:when>
 82    <c:when test="<%= SessionErrors.contains(request, TransformException.class.getName()) %>">
 83        <h3 class="portlet-msg-error">
 84            <liferay-ui:message key="internal-server-error" />
 85        </h3>
 86
 87        <liferay-ui:message key="an-error-occurred-while-processing-the-requested-resource" />
 88
 89        <br /><br />
 90
 91        <code><%= HtmlUtil.escape(url) %></code>
 92
 93        <br /><br />
 94
 95        <%
 96        TransformException te = (TransformException)SessionErrors.get(request, TransformException.class.getName());
 97        %>
 98
 99        <div>
100            <%= StringUtil.replace(te.getMessage(), new String[] {"<", "\n"}, new String[] {"&lt;", "<br />\n"}) %>
101        </div>
102    </c:when>
103    <c:when test="<%= noSuchResourceException %>">
104        <h3 class="portlet-msg-error">
105            <liferay-ui:message key="not-found" />
106        </h3>
107
108        <liferay-ui:message key="the-requested-resource-was-not-found" />
109
110        <br /><br />
111
112        <code><%= HtmlUtil.escape(url) %></code>
113    </c:when>
114    <c:otherwise>
115        <h3 class="portlet-msg-error">
116            <liferay-ui:message key="internal-server-error" />
117        </h3>
118
119        <liferay-ui:message key="an-error-occurred-while-accessing-the-requested-resource" />
120
121        <br /><br />
122
123        <code><%= HtmlUtil.escape(url) %></code>
124
125        <%
126        for (String key : SessionErrors.keySet(request)) {
127            Object value = SessionErrors.get(request, key);
128
129            if (value instanceof Exception) {
130                Exception e = (Exception)value;
131
132                _log.error(e, e);
133            }
134        }
135        %>
136
137    </c:otherwise>
138</c:choose>
139
140<div class="separator"><!-- --></div>
141
142<a href="javascript:history.go(-1);">&laquo; <liferay-ui:message key="back" /></a>
143
144<%!
145private static Log _log = LogFactoryUtil.getLog("portal-web.docroot.html.portal.status_jsp");
146%>

File path:
<hook home>/docroot/WEB-INF/jsp/html/portal/status.jsp


To use the custom 404.jsp be sure to configure it your portail-ext.properties like so :
1#Page 404
2layout.friendly.url.page.not.found=/errors/404.jsp


I hope this can help anyone wanting to customize Liferay.

Cheers!
Stefan Walter
RE: Redirecting to custom 404 error pages
May 7, 2015 12:24 AM
Answer

Stefan Walter

Rank: New Member

Posts: 5

Join Date: April 10, 2012

Recent Posts

Matthieu Levesque:

And we had to modify the status portlet so that it doesn't send an HTTP code other that 200.


Unfortunately this is problematic if the pages are public and meant to be crawled by search engines (which you want to let know, that a page was removed for example). Citing from the Google Webmaster Tools Help:


Returning a code other than 404 or 410 for a non-existent page (or redirecting users to another page, such as the homepage, instead of returning a 404) can be problematic. Such pages are called soft 404s, and can be confusing to both users and search engines.
Matthieu Levesque
RE: Redirecting to custom 404 error pages
July 8, 2015 8:03 AM
Answer

Matthieu Levesque

Rank: Junior Member

Posts: 62

Join Date: February 13, 2009

Recent Posts

Stefan Walter:
Matthieu Levesque:

And we had to modify the status portlet so that it doesn't send an HTTP code other that 200.


Unfortunately this is problematic if the pages are public and meant to be crawled by search engines (which you want to let know, that a page was removed for example). Citing from the Google Webmaster Tools Help:


Returning a code other than 404 or 410 for a non-existent page (or redirecting users to another page, such as the homepage, instead of returning a 404) can be problematic. Such pages are called soft 404s, and can be confusing to both users and search engines.


I think my response was a bit misleading. We had to modify the status portlet because it was sending a 200 code for the /not-found page for the missing page. So for example, we have a dead link www.example.com/this-page-doesnt-exists, initially we had an 200 code but after our modification we do get a 404 error. Hope this clarify the confusion.
Niccolò Pasquetto
RE: Redirecting to custom 404 error pages
March 29, 2016 4:08 AM
Answer

Niccolò Pasquetto

Rank: New Member

Posts: 13

Join Date: April 11, 2013

Recent Posts

Hi guys, I've tried the very good solution proposed by Matthieu but in my situation, with a particular cluster/virtual hosting/networking/firewall configuration there is a problem in establishing the connection to check if the "not-found" page exists.

So I've used a completly different approach to resolve this issue: I've set this configuration in the Apache web server for each virtual host that proxy to a site in the Liferay instance:

1<VirtualHost *:80>
2    [...]
3    ProxyErrorOverride On
4    ErrorDocument 404 /not-found
5    [...]
6</VirtualHost>


and then, in each site, I've created an hidden page with "/not-found" as friendly URL.

In this way Apache in case of a 404 response instead of return the "standard" 404 Liferay page, return the one specified by the ErrorDocument directive (it's not a redirect).

What do you think about this solution?