I wrote on my .htaccess an if to check if the *mod_rewrite* is installed and throw error 500 if not.
ErrorDocument 500 /500.html
<IfModule !mod_rewrite.c>
Error "mod_rewrite not installed"
</IfModule>
If i get an 500 error by it will show the 500.html. But if it gets that same error from the Error directive, it will show the default error page instead. Why ? How do i fix it ?
Well, after thinking a lot about it and reading a bit, i believe that the Error function simply makes the .htaccess parsing to be cancelled - and the error to be logged - and then throw an 500 error from the apache config that has been parsed before this one (for example, an .htaccess from another folder over this one or the httpd.conf from apache)
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
Ive made this .htaccess file
ErrorDocument 404 /404.php
ErrorDocument 500 /maintenance.php
But when i try to access to http://www.mupiz.com/admin/TESTS.php (there's a parse error in it)
The serveur does not redirect to maintenance.php
Any ideas ?
Thanks
You have some confusion about custom error handling.
500 is for Internal Server Error in Apache before it invokes PHP module. Once PHP module is invoked it is up to the PHP to handle everything. Parse error anyway is not a 500 and even if you make PHP cause 500, Apache's 500 handler won't be invoked.
Here's my .htaccess in /var/www/avatars (I can confirm this .htaccess is being read and executed);
ErrorDocument 404 /var/www/avatars/default.jpg
Here is what I get with a 404 page:
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Here is default.jpg:
https://coinchat.org:8001/avatars/default.jpg
Why is this error happening? It was working a day ago
Tried this?
ErrorDocument 404 /default.jpg
If not, did you make any other changes to .htaccess or httpd.conf or anything?
I have installed apache2 on my ubuntu machine. As I need to work with subdomains I created a proper entry in sites-available which looks like this:
<VirtualHost *:80>
ServerName xxx.localhost
DocumentRoot /var/www/
</VirtualHost>
I also enabled mod_rewrite (and changed "AllowOverride All" in my sites-available/default file) but other than that nothing else was changed.
My .htaccess file does work, and I wanted to handle some error codes. Doing so with 404 worked pretty well, but for some reason other errors don't seem to work. I'm mostly interested in handling error 400:
ErrorDocument 400 /400.php
ErrorDocument 404 /404.php
Is there anything else I should look at? I couldn't seem to find any place where 404 are allowed while other error codes aren't.
If the php is returning the 400 error, then php should generate the error document.
Use something like:
if( $someError )
{
http_response_code(400);
include("{$_SERVER['DOCUMENT_ROOT']}/400.php");
exit();
}
From the Apache documentation:
Although most error messages can be overriden, there are certain circumstances where the internal messages are used regardless of the setting of ErrorDocument. In particular, if a malformed request is detected, normal request processing will be immediately halted and the internal error message returned. This is necessary to guard against security problems caused by bad requests.
Try adding it directly in the httpd.conf and restart Apache.
I have a number of ErrorDocuments setup in my .htaccess file for errors such as 404, 401, 403 etc which all redirect to my error page but the ErrorDocument set for a 500 error is never displayed when PHP reports a 500. The 500 code is sent to the browser and the output is blank. Is there something special I need to do to enable 500 error documents for use with PHP?
My directives look like this:
ErrorDocument 401 /errorpage.php?error=401
ErrorDocument 403 /errorpage.php?error=403
ErrorDocument 404 /errorpage.php?error=404
ErrorDocument 500 /errorpage.php?error=500
I've looked through the php.ini and can't see anything that would obviously override the Apache settings and there are no ErrorDocument directives in my httpd.conf either. Anywhere else I should be looking?
Thanks in advance.
See this answer to a very similar question. Basically, PHP isn't hardly ever going to trigger a 500.
You may need to add the ErrorDocument declaration earlier in the Apache conf chain. If you add this to a vhost conf it may not be called.
I happened to encounter the same issue while working with codeigniter and Imagick. imagick was setting a 500 HTTP error when something went wrong and in that case Codeigniter's custom 500 message was not displayed.
I resolved this by adding try-catch to all Imagick functions.Check that where from the 500 issue is arising and then add a try-catch there.As for
ErrorDocument 500 /errorpage.php?error=500
,I read loads online about the same where some people claim that this solved their similar issue, others say that it wouldnt help as Apache has handed over the control to PHP.Maybe some php code is setting Headers to 500 and that would probably lead to the browser displaying its custom 500 error message.
I don't believe Apache will let you run PHP files for 500 errors because the error page could generate an error. Try rendering out your 500 error to an HTML file and point your directives at that.