Reset/Remove ErrorDocument via htaccess - apache

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.

Related

How to disable Apache ErrorDocument Message

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

Change Default Error Catch in htaccess?

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.

How can I remove handlers for 4xx / 5xx errors in GoDaddy?

I have a PHP entry point which returns a json object (using json_encode) and returns a certain status code among (500, 400, 410, 409, 404, 200).
However, when I hit the page using a REST client AND the response status is not 200, I get an error page being rendered (text/html - yes, I did not forget including an Accept: application/json header).
How do I specify to REMOVE ANY ERROR PAGE handler in GoDaddy? I care about this only in a subdomain / subfolder (http://subdomain.example.com/ or http://example.com/subdomain/).
I figure I must do it in a .htaccess file but: what must I put inside to override the handlers?
Edit: NO! It is an IIS. I had to use a WebConfig
You can place these ErrorDocument directives in the DocumentRoot of subdomain to reset all the handlers set earlier:
ErrorDocument 500 default
ErrorDocument 400 default
ErrorDocument 410 default
ErrorDocument 409 default
ErrorDocument 409 default
ErrorDocument 200 default

Redirect via htacces to error pages (not found & Internal Server error)

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.....

.htaccess forcing error pages on SSL

I have the following piece of code in my .htaccess file to force redirecting to custom error pages:
ErrorDocument 404 /ErrorPages/404.php
ErrorDocument 403 /ErrorPages/403.php
ErrorDocument 400 /ErrorPages/generalError.php
ErrorDocument 401 /ErrorPages/generalError.php
ErrorDocument 500 /ErrorPages/generalError.php
Everything works fine on port 80, but when it comes to SSL, the standard error pages are shown.
To be more specific:
http:www.mydomain.com/NoExistingPage.php redirects to the custom error page
https:www.mydomain.com/NoExistingPage.php DOES NOT redirect to the custom error page
am I missing something here?
Thanks in advance
Try putting a duplicate .htaccess file in the /secured folder and see if that works. The vhost for the https daemon is probably using /secured as doc_root which means even if the .htaccess from the regular doc_root is below the secured folder it will be ignored.