Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The 404 Handler

What should the user see when they ask for page that doesn't exist ?
If using Tomcat you can use the web.xml file to specify an error page.

...

Code Block
/index/404.html

Edit the magnoliaPublic web.xml (inside webapps\magnoliaPublic\WEB-INF\web.xml)
and add the following section:{{

Code Block

  <error-page>

...


     <error-code>404</error-code>

...


     <location>/admintemplates/404.jsp</location>

...


  </error-page>

...

 

Now, create a 404.jsp file inside your \webapps\magnoliaPublic\admintemplates directory
that contains the following jsp code{{

Code Block

<%

...


response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

...


String contextName = request.getContextPath();

...


String newLocn = contextName + "/index/404.html";

...


response.setHeader("Location",newLocn);

...


%>

...


What will happen is that if a user requests a page that doesn't exist inside
your magnoliaPublic context then Tomcat will redirect the user to the
/admintemplates/404.jsp page which then redirects to your /index/404.html page.

Why must you do it this way?? Well, your web.xml has to point to a file that actually
exists somewhere in your webapps directory, not to a 'virtual' file in your Magnolia
repository. If you doubt this, try replacing /admintemplates/404.jsp with
/magnoliaPublic/index/404.html and see what happens. We point the web.xml to a 'real' file
and then have that real file perform a redirect to your magnolia generated 404.html file.

This method tested with 2.1-RC4 and 2.1.3

Valid for v21 Valid for v3

Now to make this work with magnolia v 3.5.x you need to define a bypass for a custom jsp page created above. Go to the configuration menu and create new contentNode under
server/filters/bypasses and call it 404 for this node create dataNode class and set it to info.magnolia.voting.voters.URIStartsWithVoter and dataNode pattern with value pointing to your 404.jsp (i.e. /admintemplates/404.jsp in the case of example above)

In its previous incarnation on JspWiki, this page was last edited on Mar 31, 2007 10:07:56 PM by Magnolia
Other known authors include :

  • RamonBuckland
  • RamonBuckland
  • 61.145.233.118
  • 212.163.159.14
  • Jgibbens
  • 155.97.16.124
  • BorisKraft
  • BorisKraft