stop apache injecting it's own 404 not found page to the custom 404 error page - apache

I'm having a problem implementing custom 404 error pages. my setup is a front-end apache 2.2.6 proxy request other than static file to the backend app server(apache 1.3.36)
i send 404 header back along with error page when user request a non-existing page to the backend server. I do get the error page back but somehow the backend apache server injects its own 404 not found page in the error page as well.
here is what injected to the not found page by apache:
Not Found
The requested URL /product/8jd4776 was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.36 Server at www.example.com Port 8888
any idea why this is happening?

set "ProxyErrorOverride On" with ErrorDocument in the front-end apache server solve the problem.

The content length of your custom 404 message must be 512 bytes or more.

Related

Apache server status codes

Is there a way, on apache server, to make a specified page, to send code 404 in browser?
I work on an application, where if you tap a url that is not recognised, the application sends code 302, and makes a redirect instead of a page error.html who send code 200 which is normal because is a page who exist.
I need to modify the code for page error.html in 404 from httpd.conf.
Can you help me please?
I've tried with ErrorDocument 404 /error, but the application does not send 404, it sends 302. I need to rewrite this 302 in 404.
create an error page 404.html on the httpd DocumentRoot.
Add ErrorDocument 404 /404.html in httpd.conf.
Restart Apache and access a page that does not exist.

How to show custom 404 error page when using `AllowEncodedSlashes On`

I recently came across the AllowEncodedSlashes Apache directive:
https://intranet.csc.liv.ac.uk/manual/mod/core.html#AllowEncodedSlashes
If I hit a URL like this: www.domain.com/my/page/%2F/etcetera, Apache shows its default 404 error page:
However, I would like to return a custom 404 error page but how can I do it within my .htaccess? This doesn't work:
ErrorDocument 404 /entrypoint.php
I know I can do it if I have access to the server's httpd.conf configuration file (I tested locally). But what if I do not have access to the configuration on a remote site? Is there a way?
Thank you for the attention.

OpenCart maintenance mode 503 error

I install directadmin with CB2 + Apache + MariaDB 10.1.31 + PHP 5.6.34.
When I upload OpenCart and enable maintenance mode, Apache shows the 503 error page instead of maintenance.tpl.
I checked the catalog/controller/common/maintenance.php and found the following code:
if ($this->request->server['SERVER_PROTOCOL'] == 'HTTP/1.1') {
$this->response->addHeader('HTTP/1.1 503 Service Unavailable');
} else {
$this->response->addHeader('HTTP/1.0 503 Service Unavailable');
}
$this->response->addHeader('Retry-After: 3600');
I think the problem is that Apache does not handle the 503 Header correctly. When I change the web server to LiteSpeed, it is ok.
To check you can compare these two versions of the site. Both of them have the maintenance mode enabled, but:
The first is OK - http://takjens.com/
The second is not - http://server3.lammer.ir/
Please let me know how to fix this problem.
Here LiteSpeed has custom error page configured, while Apache shows default 503 error page, as defined in the response header.
To make Apache display the custom error page, do the following:
Add the custom error page directive to the Apache configuration or into the .htaccess file for the domain. Specify the path to the maintenance.tpl file relatively to the configured ServerRoot:
ErrorDocument 503 /path/to/maintenance.tpl
.tpl file extension is not something that Apache can serve by default. I order to process it properly, the correct file type should be specified for this extension either in Apache configuration or via .htaccess file:
AddType text/html tpl

Apache redirects in case of http errors

We have a web application. The backend is an Apache Web Server (Version 2.2).
As described in the following document
https://httpd.apache.org/docs/2.4/custom-error.html
we have configured an ErrorDocument for 404 which redirects to a cgi program.
ErrorDocument 404 /cgi-bin/log_false_request.pl
In the program "log_false_request" we write the ip address, the user-agent and
the original URL (request uri) of the request to a log file.
When an http error 500 happens and the request is a post, it would also be
interesting to have the post body.
Does apache also redirect the response body in case of a post request?
Thanks alot in advance.

Redirect to external site on 500 error with .htaccess

I am working on a website (scratchyone.com). I need to have my .htaccess redirect to an external page
http://scratchywon.github.io/scratchyone.com/errors/500.html
on a 500 error. I am forcing a 500 with php.
http://scratchyone.com/500/
Here is my current code:
ErrorDocument 500 http://scratchywon.github.io/scratchyone.com/errors/500.html
EDIT: ErrorDocument 404 http://scratchywon.github.io/scratchyone.com/errors/500.html works
Now that I am using php to send the 500 error, the page doesn't display. It just displays the browser's default "500: Could not display"
Internal error in .htaccess not relay custom ErrorDocument (!) and simulate 500 error via PHP is not quite possible - when your script run it's too late - error document redirection is handled by apache mod_core (!) and PHP only send status.
So I think you can forget about PHP 500-simulation.
Try to make a directory next to main .htaccess and inside make faulty .htaccess
Or maybe this will be helpful for you:
https://www.digitalocean.com/community/tutorials/how-to-configure-apache-to-use-custom-error-pages-on-ubuntu-14-04
Section about 500 provide information how to simulate this error via bad proxy.