How to configure dispatchers to use custom error pages? | Community
Skip to main content
LinearGradient
Level 6
October 16, 2015
Solved

How to configure dispatchers to use custom error pages?

  • October 16, 2015
  • 6 replies
  • 7503 views

Hi,

We have created some custom error handler pages (in /apps/sling/servlet/errorhandler/) and they are being served as expected when we hit our publish instances directly (e.g. http://example.com:4503/foo).

However when we access a web site through the dispatcher, the dispatcher does not use our custom pages and renders the standard 404 error page.

Is there a way to configure the dispatcher to use our custom error pages as well?

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Venugopal_Gumma

if you want to get a default page on hitting a URL without file extension(http://example.com:4503/foo instead of http://example.com:4503/foo/index.html) first you must configure the sling:redirect (please refer http://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html
Please find attached screenshot showing what happens when you hit homepage of geometrix .. take notice ..sling:redirect=true and sling:resourceType=foundation/components/redirect 

Instead of redirect if you want to display error page .. 

here are some notes .. 

http://www.slideshare.net/gummadal/the-secret-life-of-a-dispatcher

http://dev.day.com/docs/en/cq/current/developing/customizing_error_handler_pages.html

 

http://httpd.apache.org/docs/2.2/custom-error.html

Use of ErrorDocument is enabled for .htaccess files when the AllowOverride is set accordingly.

Here are some examples...

ErrorDocument 500 /cgi-bin/crash-recover 
ErrorDocument 500 "Sorry, our script crashed. Oh dear" 
ErrorDocument 500 http://xxx/ 
ErrorDocument 404 /Lame_excuses/not_found.html 
ErrorDocument 401 /Subscription/how_to_subscribe.html

The syntax is,

ErrorDocument <3-digit-code> <action>

where the action can be,

  1. Text to be displayed. Wrap the text with quotes (").
  2. An external URL to redirect to.
  3. A local URL to redirect to.

6 replies

Venugopal_Gumma
Venugopal_GummaAccepted solution
Level 3
October 16, 2015

if you want to get a default page on hitting a URL without file extension(http://example.com:4503/foo instead of http://example.com:4503/foo/index.html) first you must configure the sling:redirect (please refer http://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html
Please find attached screenshot showing what happens when you hit homepage of geometrix .. take notice ..sling:redirect=true and sling:resourceType=foundation/components/redirect 

Instead of redirect if you want to display error page .. 

here are some notes .. 

http://www.slideshare.net/gummadal/the-secret-life-of-a-dispatcher

http://dev.day.com/docs/en/cq/current/developing/customizing_error_handler_pages.html

 

http://httpd.apache.org/docs/2.2/custom-error.html

Use of ErrorDocument is enabled for .htaccess files when the AllowOverride is set accordingly.

Here are some examples...

ErrorDocument 500 /cgi-bin/crash-recover 
ErrorDocument 500 "Sorry, our script crashed. Oh dear" 
ErrorDocument 500 http://xxx/ 
ErrorDocument 404 /Lame_excuses/not_found.html 
ErrorDocument 401 /Subscription/how_to_subscribe.html

The syntax is,

ErrorDocument <3-digit-code> <action>

where the action can be,

  1. Text to be displayed. Wrap the text with quotes (").
  2. An external URL to redirect to.
  3. A local URL to redirect to.
October 16, 2015

Hi,

An easy way would be to store the custom error pages in the dispatcher server then configure Apache to point 404 pages to the error page.

LinearGradient
Level 6
October 16, 2015

I am looking for a way to serve them from the publish instance and maybe cache them in the dispatcher. Is there a way to do this?

Level 6
October 16, 2015

You can configure the ErrorDocument part of your virual host in the Apache HTTPD configuration

ErrorDocument 500 /apps/sling/servlet/errorhandler/500.html
ErrorDocument 404 /apps/sling/servlet/errohandler/404.html

See http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

/O

 

p0990m
October 25, 2017

Hi,

I tried using the ErrorDocument in the vhost file in disptacher which is pointing to the error pages(/content/abc/404.html, /content/abc/500.html) for 500, 404 respectively.But when we see the Status code in network tab, we see as 200. But we need exact status code,as 404 or 500. I tried using <%slingResponse.setStatus(404);%> in the jsp of the page component of /content/abc/404.html. But it shows error like ,shown in the pic below , can anyone suggest on this?

May 4, 2023

i have a multilingual site in same domain, my requirement is to redirect different error pages for different site.