Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to configure dispatchers to use custom error pages?

Avatar

Level 7

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.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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.

View solution in original post

6 Replies

Avatar

Correct answer by
Level 2

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.

Avatar

Former Community Member

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.

Avatar

Level 7

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?

Avatar

Level 6

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

 

Avatar

Level 1

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?

1333163_pastedImage_0.png

Avatar

Level 1

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