掲示板

Redirecting to custom 404 error pages

12年前 に Phoenix Zerin によって更新されました。

Redirecting to custom 404 error pages

Junior Member 投稿: 60 参加年月日: 11/06/28 最新の投稿
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:

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


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.:

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


Same result: silent failure.

Am I going down the right path? How should I implement a redirect (internal [preferably] or external) on a 404 error?
thumbnail
12年前 に jelmer kuperus によって更新されました。

RE: Redirecting to custom 404 error pages (回答)

Liferay Legend 投稿: 1191 参加年月日: 10/03/10 最新の投稿
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

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


in the 404-searchworkings.jsp file

<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@ page import="com.liferay.portal.NoSuchLayoutException" %>
<%@ page import="com.liferay.portal.service.LayoutLocalServiceUtil" %>
<%@ page import="com.liferay.portal.util.WebKeys" %>
<%@ page import="com.liferay.portal.model.LayoutSet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--
    It seems we cannot directly specify a portal page in the layout.friendly.url.page.not.found property
    So do a jstl import and fake it
--%>
<%! private static final String NOT_FOUND_LAYOUT_FRIENDLY_URL = "/not-found"; %>
<%
LayoutSet layoutSet = (LayoutSet)request.getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET);

boolean notFoundPageExists = true;
try {
    LayoutLocalServiceUtil.getFriendlyURLLayout(layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
            NOT_FOUND_LAYOUT_FRIENDLY_URL);
} catch (NoSuchLayoutException e) {
    notFoundPageExists = false;
}
%>
<c:if test="<%= notFoundPageExists %>">
    <c:import url="<%= PortalUtil.getPortalURL(request) + NOT_FOUND_LAYOUT_FRIENDLY_URL + " ;jsessionid=" + session.getId() %>" />
</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
thumbnail
12年前 に David García González によって更新されました。

RE: Redirecting to custom 404 error pages

Regular Member 投稿: 127 参加年月日: 09/07/14 最新の投稿
Hi everybody!

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

Thanks!
thumbnail
12年前 に jelmer kuperus によって更新されました。

RE: Redirecting to custom 404 error pages

Liferay Legend 投稿: 1191 参加年月日: 10/03/10 最新の投稿
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
thumbnail
12年前 に David García González によって更新されました。

RE: Redirecting to custom 404 error pages

Regular Member 投稿: 127 参加年月日: 09/07/14 最新の投稿
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.
thumbnail
12年前 に jelmer kuperus によって更新されました。

RE: Redirecting to custom 404 error pages

Liferay Legend 投稿: 1191 参加年月日: 10/03/10 最新の投稿
That is basically what i am doing in the example
thumbnail
12年前 に David García González によって更新されました。

RE: Redirecting to custom 404 error pages

Regular Member 投稿: 127 参加年月日: 09/07/14 最新の投稿
jelmer kuperus:
That is basically what i am doing in the example


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

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


Thanks!!!
thumbnail
12年前 に Chris Becker によって更新されました。

RE: Redirecting to custom 404 error pages

Regular Member 投稿: 112 参加年月日: 10/06/11 最新の投稿
Hi Jelmer;

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

Regards,

--Chris
12年前 に Paolo Pilitti によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 51 参加年月日: 11/04/13 最新の投稿
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?
12年前 に Paolo Pilitti によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 51 参加年月日: 11/04/13 最新の投稿
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?
thumbnail
11年前 に Thiago Leão Moreira によって更新されました。

RE: Redirecting to custom 404 error pages

Liferay Legend 投稿: 1449 参加年月日: 07/10/10 最新の投稿
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.
thumbnail
10年前 に Achmed Tyrannus Albab によって更新されました。

RE: Redirecting to custom 404 error pages

Regular Member 投稿: 158 参加年月日: 10/03/05 最新の投稿
Jelmer Kuperus:
..
layout.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.
10年前 に Harsha Mhaske によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 15 参加年月日: 08/09/26 最新の投稿
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
10年前 に Juha Anttila によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 14 参加年月日: 12/10/19 最新の投稿
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 [stdout] (http--0.0.0.0-8080-1) javax.servlet.forward.request_uri
07:24:40,247 INFO [stdout] (http--0.0.0.0-8080-1) javax.servlet.forward.context_path
07:24:40,247 INFO [stdout] (http--0.0.0.0-8080-1) javax.servlet.forward.servlet_path
07:24:40,247 INFO [stdout] (http--0.0.0.0-8080-1) javax.servlet.forward.path_info
07:24:40,248 INFO [stdout] (http--0.0.0.0-8080-1) COMPANY
07:24:40,248 INFO [stdout] (http--0.0.0.0-8080-1) com.liferay.portal.kernel.util.CookieKeys
07:24:40,248 INFO [stdout] (http--0.0.0.0-8080-1) class com.liferay.portal.servlet.filters.cache.CacheFilterSKIP_FILTER
07:24:40,249 INFO [stdout] (http--0.0.0.0-8080-1) CURRENT_COMPLETE_URL
07:24:40,249 INFO [stdout] (http--0.0.0.0-8080-1) FRIENDLY_URL
07:24:40,249 INFO [stdout] (http--0.0.0.0-8080-1) com.liferay.portal.servlet.filters.i18n.I18nFilterSKIP_FILTER
07:24:40,249 INFO [stdout] (http--0.0.0.0-8080-1) COMPANY_ID
07:24:40,250 INFO [stdout] (http--0.0.0.0-8080-1) com.liferay.portal.servlet.filters.strip.StripFilterSKIP_FILTER
07:24:40,250 INFO [stdout] (http--0.0.0.0-8080-1) com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterSECURE_RESPONSE
07:24:40,250 INFO [stdout] (http--0.0.0.0-8080-1) User-Agent
07:24:40,250 INFO [stdout] (http--0.0.0.0-8080-1) CURRENT_URL
07:24:40,251 INFO [stdout] (http--0.0.0.0-8080-1) com.liferay.portal.servlet.filters.gzip.GZipFilterSKIP_FILTER
07:24:40,251 INFO [stdout] (http--0.0.0.0-8080-1) INVOKER_FILTER_URI

so (LayoutSet)request.getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET) is null.
9年前 に Juha Anttila によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 14 参加年月日: 12/10/19 最新の投稿
Anybody?

Is the hook version correct way to go with Liferay 6.2 custom 404 page?
9年前 に Luis Silva によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 42 参加年月日: 13/04/18 最新の投稿
Hi,
I'm also using liferay 6.2.
Juha did you solve your issue?
9年前 に Vidmantas Banaitis によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 1 参加年月日: 14/03/25 最新の投稿
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
9年前 に Juha Anttila によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 14 参加年月日: 12/10/19 最新の投稿
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 :

<error-page>
		<error-code>404</error-code>
		<location>/errors/code.jsp</location>
</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.
9年前 に Pavel Fomin によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 2 参加年月日: 14/11/26 最新の投稿
Setting layout.friendly.url.page.not.found to the friendly url of a page works in Liferay 6.2.
layout.friendly.url.page.not.found = /web/guest/not-found

where not-found is the friendly url of the page.
thumbnail
9年前 に Matthieu Levesque によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 64 参加年月日: 09/02/13 最新の投稿
Pavel Fomin:
Setting layout.friendly.url.page.not.found to the friendly url of a page works in Liferay 6.2.
layout.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.
thumbnail
9年前 に Matthieu Levesque によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 64 参加年月日: 09/02/13 最新の投稿
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:
&lt;%@ page import="javax.servlet.http.HttpServletRequest" %&gt;
&lt;%@ page import="java.util.regex.Matcher" %&gt;
&lt;%@ page import="java.net.URL" %&gt;
&lt;%@ page import="java.net.URLConnection" %&gt;
&lt;%@ page import="java.util.regex.Pattern" %&gt;
&lt;%@ page import="com.liferay.portal.kernel.util.Validator" %&gt;
&lt;%@ page import="com.liferay.portal.kernel.util.ParamUtil" %&gt;
&lt;%@ page import="com.liferay.portal.util.Portal" %&gt;
&lt;%@ page import="com.liferay.portal.util.PortalUtil" %&gt;
&lt;%@ page import="com.liferay.portal.NoSuchLayoutException" %&gt;
&lt;%@ page import="com.liferay.portal.service.LayoutLocalServiceUtil" %&gt;
&lt;%@ page import="com.liferay.portal.util.WebKeys" %&gt;
&lt;%@ page import="com.liferay.portal.model.LayoutSet" %&gt;
&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
&lt;%--
    It seems we cannot directly specify a portal page in the layout.friendly.url.page.not.found property
    So do a jstl import and fake it
--%&gt;
&lt;%! private static final String NOT_FOUND_LAYOUT_FRIENDLY_URL = "not-found"; %&gt;
&lt;%

LayoutSet layoutSetCustom = (LayoutSet)request.getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET);

boolean notFoundPageExists = false;

HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(request);

String url = ParamUtil.getString(request, "previousURL");

if (Validator.isNull(url)) {
	url = PortalUtil.getCurrentURL(request);
}


//Valide que ce n'est pas la page not-found
Pattern notFoundUrlPat = Pattern.compile(NOT_FOUND_LAYOUT_FRIENDLY_URL+"$");

//Get the community URL
String communityUrl = "/";
Pattern siteUrlPat = Pattern.compile("/(web|group)/[^/]+/");
Matcher m = siteUrlPat.matcher(url);

if(m.find()) {
	communityUrl = m.group();
}

boolean isSsl = false;
String portalUrl = PortalUtil.getPortalURL(request);
if(portalUrl.startsWith("https")) {
	/*
	 * Force all inner requests to be non-SSL because of this bug:
	 * 
	 *  http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6521495
	 * http://stackoverflow.com/questions/6851461/java-why-does-ssl-handshake-give-could-not-generate-dh-keypair-exception
	 */
	isSsl = true;
	
	portalUrl = portalUrl.replaceAll("^https", "http");
}

communityUrl = portalUrl + communityUrl;

String redirect = "";

if(!notFoundUrlPat.matcher(url).find()) {
	String checkUrl = communityUrl+NOT_FOUND_LAYOUT_FRIENDLY_URL;
	
	//Check if a page not-found exists in the community
	try {
		URL obj = new URL(checkUrl);
		URLConnection conn = obj.openConnection();
		String header = conn.getHeaderField(null);
		if(header.contains("200")) {
			notFoundPageExists=true;
			redirect = communityUrl+NOT_FOUND_LAYOUT_FRIENDLY_URL;
		}
	} catch (Exception e) {}
}

if(!notFoundPageExists) {
	ServletContext servletContext = session.getServletContext();

	int status = HttpServletResponse.SC_NOT_FOUND;

	redirect = portalUrl +
		Portal.PATH_MAIN +
		"/portal/status?status="+status+
		"&amp;exception=java.lang.NoSuchException&amp;previousURL="+url;
}
%&gt;<c:import var="data" url="<%= redirect %>" charEncoding="UTF-8" />&lt;%
String data = (String)pageContext.getAttribute("data");

//Change the links back to SSL if the original request was SSLed
if(isSsl) {
	//Hack the escaping of some of the portal links...
	data = data
			.replaceAll(":", ":")
			.replaceAll("/", "/")
			.replaceAll(".", "\\.");
	
	String nonSslPortalLink = portalUrl;
	String sslPortalLink = nonSslPortalLink.replaceAll("^http", "https");
	
	data = data.replaceAll(nonSslPortalLink, sslPortalLink);
}
%&gt;&lt;%=data%&gt;

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).
&lt;%--
/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%&gt;

&lt;%@ include file="/html/portal/init.jsp" %&gt;

&lt;%
int status = ParamUtil.getInteger(request, "status");

/*
 * We don't want import from the 404 to fail because of an HTTP error
 * so we don't set the code.
 * 
if (status &gt; 0) {
	response.setStatus(status);
}*/

String exception = ParamUtil.getString(request, "exception");

String url = ParamUtil.getString(request, "previousURL");

if (Validator.isNull(url)) {
	url = PortalUtil.getCurrentURL(request);
}

url = themeDisplay.getPortalURL() + url;

boolean noSuchResourceException = false;

for (String key : SessionErrors.keySet(request)) {
	key = key.substring(key.lastIndexOf(StringPool.PERIOD) + 1);

	if (key.startsWith("NoSuch") &amp;&amp; key.endsWith("Exception")) {
		noSuchResourceException = true;
	}
}

if (Validator.isNotNull(exception)) {
	exception = exception.substring(exception.lastIndexOf(StringPool.PERIOD) + 1);

	if (exception.startsWith("NoSuch") &amp;&amp; exception.endsWith("Exception")) {
		noSuchResourceException = true;
	}
}
%&gt;

<c:choose>
	<c:when test="<%= SessionErrors.contains(request, PrincipalException.class.getName()) %>">
		<h3 class="portlet-msg-error">
			<liferay-ui:message key="forbidden" />
		</h3>

		<liferay-ui:message key="you-do-not-have-permission-to-access-the-requested-resource" />

		<br><br>

		<code>&lt;%= HtmlUtil.escape(url) %&gt;</code>
	</c:when>
	<c:when test="<%= SessionErrors.contains(request, PortalException.class.getName()) || SessionErrors.contains(request, SystemException.class.getName()) %>">
		<h3 class="portlet-msg-error">
			<liferay-ui:message key="internal-server-error" />
		</h3>

		<liferay-ui:message key="an-error-occurred-while-accessing-the-requested-resource" />

		<br><br>

		<code>&lt;%= HtmlUtil.escape(url) %&gt;</code>
	</c:when>
	<c:when test="<%= SessionErrors.contains(request, TransformException.class.getName()) %>">
		<h3 class="portlet-msg-error">
			<liferay-ui:message key="internal-server-error" />
		</h3>

		<liferay-ui:message key="an-error-occurred-while-processing-the-requested-resource" />

		<br><br>

		<code>&lt;%= HtmlUtil.escape(url) %&gt;</code>

		<br><br>

		&lt;%
		TransformException te = (TransformException)SessionErrors.get(request, TransformException.class.getName());
		%&gt;

		<div>
			&lt;%= StringUtil.replace(te.getMessage(), new String[] {"&lt;", "\n"}, new String[] {"&lt;", "<br>\n"}) %&gt;
		</div>
	</c:when>
	<c:when test="<%= noSuchResourceException %>">
		<h3 class="portlet-msg-error">
			<liferay-ui:message key="not-found" />
		</h3>

		<liferay-ui:message key="the-requested-resource-was-not-found" />

		<br><br>

		<code>&lt;%= HtmlUtil.escape(url) %&gt;</code>
	</c:when>
	<c:otherwise>
		<h3 class="portlet-msg-error">
			<liferay-ui:message key="internal-server-error" />
		</h3>

		<liferay-ui:message key="an-error-occurred-while-accessing-the-requested-resource" />

		<br><br>

		<code>&lt;%= HtmlUtil.escape(url) %&gt;</code>

		&lt;%
		for (String key : SessionErrors.keySet(request)) {
			Object value = SessionErrors.get(request, key);

			if (value instanceof Exception) {
				Exception e = (Exception)value;

				_log.error(e, e);
			}
		}
		%&gt;

	</c:otherwise>
</c:choose>

<div class="separator"><!-- --></div>

<a href="javascript:history.go(-1);">« <liferay-ui:message key="back" /></a>

&lt;%!
private static Log _log = LogFactoryUtil.getLog("portal-web.docroot.html.portal.status_jsp");
%&gt;

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 :
#Page 404
layout.friendly.url.page.not.found=/errors/404.jsp


I hope this can help anyone wanting to customize Liferay.

Cheers!
8年前 に Stefan Walter によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 5 参加年月日: 12/04/10 最新の投稿
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.
thumbnail
8年前 に Matthieu Levesque によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 64 参加年月日: 09/02/13 最新の投稿
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.
8年前 に Niccolò Pasquetto によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 13 参加年月日: 13/04/11 最新の投稿
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:

<virtualhost *:80>
    [...]
    ProxyErrorOverride On 
    ErrorDocument 404 /not-found
    [...]
</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?
thumbnail
7年前 に Orin Fink によって更新されました。

RE: Redirecting to custom 404 error pages

Junior Member 投稿: 65 参加年月日: 10/03/25 最新の投稿
Thanks Niccolo, I was trying this approach and had the trouble until your post showed me that `ProxyErrorOverride On` had to be set so the error doc could be proxied to the backend. Great solution.
thumbnail
7年前 に Priti Mujumdar によって更新されました。

RE: Redirecting to custom 404 error pages

New Member 投稿: 1 参加年月日: 16/12/19 最新の投稿
Niccolò Pasquetto:
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:

<virtualhost *:80>
    [...]
    ProxyErrorOverride On 
    ErrorDocument 404 /not-found
    [...]
</virtualhost>
https://mytodayshoroscope.com/


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?


I was going somewhere wrong while writing the code. Thanks for the solution.

Kind Regards,
Priti