Skip to main content
LinearGradient
Level 6
Oct 16, 2015 2:27 AM UTC
Solved

How to configure dispatchers to use custom error pages?

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.
Venugopal_Gumma
Venugopal_GummaAccepted solution
Level 3
Oct 16, 2015 2:27 AM UTC

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

Level 6
Oct 16, 2015 2:27 AM UTC

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

 

Translate
LinearGradient
Level 6
Oct 16, 2015 2:27 AM UTC

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?

Translate
Oct 16, 2015 2:27 AM UTC

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.

Translate
Venugopal_Gumma
Venugopal_GummaAccepted solution
Level 3
Oct 16, 2015 2:27 AM UTC

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.
Translate
p0990m
Oct 25, 2017 12:49 PM UTC

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?

Translate
May 4, 2023 5:42 AM UTC

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

Translate