I am wondering about the error handling in AEM for multi-tenancy applications with different content structure. My applications steps are follows:
/content/firstapp/en
---- Difficulty in the multicountry and multitenancy
/content/secondapp/country-1/en
/content/secondapp/country-2/en
/content/secondapp/country-3/en
/contente/thirdapp/en
Please suggest in this case someone implemented this kind of structure in the past or have more information to do this approachae,. thanks, Sandeep
First step is to have correctly setup the error handler, where in you are setting proper error code in the response status.
Sample for error handler for 404 configurations 404.jsp
<%
if (com.day.cq.wcm.api.WCMMode.fromRequest(request) != com.day.cq.wcm.api.WCMMode.DISABLED) {
%>
<%#include file="/libs/sling/servlet/errorhandler/404.jsp"%>
<%
} else {
response.setStatus(404);
}
%>
Next step is to have apache/dispatcher configured to load correct error document (configuration in Virtual host config). This way the proper loading of error page is delegated to the apache/dispatcher -
<LocationMatch "^/content/secondapp/country-1/en/.*$">
ErrorDocument 404 "/country-1/not-found.html"
ErrorDocument 500 "/country-1/error.html"
</LocationMatch>
<LocationMatch "^/content/secondapp/country-2/en/.*$">
ErrorDocument 404 "/country-2/not-found.html"
ErrorDocument 500 "/country-2/error.html"
</LocationMatch>
<LocationMatch "^/content/secondapp/country-3/en/.*$">
ErrorDocument 404 "/country-3/not-found.html"
ErrorDocument 500 "/country-3/error.html"
</LocationMatch>
<LocationMatch "^/content/secondapp/country-4/en/.*$">
ErrorDocument 404 "/country-4/not-found.html"
ErrorDocument 500 "/country-4/error.html"
</LocationMatch>
Above configuration is based on the short URLs where in the pattern is
/content/secondapp/country-x/en/.* shortens to /country-4/en/.* and each site has its own error.html page and not-found.html
Related
I need to disable Apache 401 error message or bypass it completely , in case of errors only back end application error codes should be displayed.
Thanks
Rakesh
Add following to your .htaccess file (works if AllowOverride allows it).
ErrorDocument 401 /URL/TO/YOUR/BACKEND/RESPONSE
Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context.
More info about Apache ErrorDocument
I use host that has custom ErrorDocument settings already set in their httpd.conf and I can't edit this file (I don't have access) to solve the problem directly there.
Some background: I use an API that when something isn't right I manually set a responde code and print a json as error response to use in client side. Since I am triggering a response code (400 - Bad Request in my case) it falls directly in the catch of my Ajax request.
Their configuration for a custom 400 error page is causing this issue, the response of my API never returns because i got as response their custom page.
Is it possible to remove/reset or set it to show the page that triggered the error of an already set ErrorDocument via .htaccess?
On server where virtual server settings cannot be modified but .htaccess is accessible, this works for me:
ErrorDocument 401 default
ErrorDocument 402 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 502 default
ErrorDocument 503 default
ErrorDocument 504 default
Put it into .htaccess and it will reset error handling pages.
So my question is similar to the question posed in this page
Single ErrorDocument directive to catch all errors (.htaccess)
The above person was trying to get a dynamic error page.
However my question is slightly different (although it may still have the same answer).
I am with a shared web host who displays custom error pages by default with ads on it. I want errors to result in a real error response without ads. Do I need to individually do a:
ErrorDocument 404 /404.html
For each error? Or is there a way to just tell it to show a normal error message for all errors?
Is there some type of:
ErrorDirective JustOutputErrorInsteadOfRedirecting
Thank you in advance.
With ErrorDocument directive you can also display Your custom error messeage on the same page.
ErrorDocument 404 "Sorry, the page does not exist!"
ErrorDocument 403 "Ohh, you don't have permission to access this page!"
ErrorDocument 410 "Sorry, the page no longer exists"
You can also format these messges using html tags
ErrorDocument 404 "<h2>Sorry, the page does not exist!</h2>"
ErrorDocument 403 "<h2 style='color:blue'>Ohh, you don't have permission to access this page!</h2>"
ErrorDocument 410 "<p>Sorry, the page no longer exists</p>"
The message will appear on the same page.
Problem with custom error pages.
My server root is "C:\www" and error pages are in "C:\www\errors".
So I put a .htaccess file in "C:\www" with following:
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
ErrorDocument 500 /errors/500.html
This works for anything in "mysite.net". But I also have subdirectories like "first.mysite.net", "second.mysite.net" and so on, and .htaccess from root doest work there. It's searching for "errors" folder in these subfolders and return the default 404 page.
I've tried this:
ErrorDocument 500 C:/www/errors/500.html
ErrorDocument 500 C:\www\errors\500.html
Doesn't work.
ErrorDocument 500 http://mysite.net/errors/500.html
This works, but it makes a redirect and I don't want this. I want the browser to keep adress line the same.
Can anyone make this clear for me? Thanks.
If they are subdomains with seperate virtualhost definitions you need to check virtualhost definitions and AllowOverride settings for those subdomains. See http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride and change AllowOverride setting as needed.
can I vía .htaccess redirect when
Users finds an Internal Server Error
A not found page
Is that posible? if so, can someone help me with the rewrite rules?
edit
trying
ErrorDocument 500 /oohps.php
ErrorDocument 404 /where.php
and adding them at domain.com/oops.php and domain.com/where.php but still not loaded
Why not just use custom error responses via ErrorDocument?
ErrorDocument 500 /errors/internal-server-error.html
ErrorDocument 404 /errors/not-found.html
It is useful I am able to redirect to index page on 404 error(page not found) by modifying "ErrorDocument" in /etc/apache2/conf.d/localized-error-pages file.
Thanks.....