Most of the time the 500 “internal server error” message is due to a malfunction from the server. However, you will see below that there are several causes that explain this server response.
Bad command in a Htaccess file
A 500 error occurs when a bad command has been added to an HTaccess file of an Apache server. Most of the time, there are several cascading htaccess config files on an Apache server installation. This is important to check every htaccess file to understand from where the culprit command comes from.
A PHP script error
Sometimes a PHP script triggers the 500 internal error message. After modifying a PHP file, the error vanishes and the server responds to the request. The webmaster will not be able to get additional information about the PHP error. Maybe, it would be useful to look into the PHP log files on the server to find the root cause of the issue. A PHP 500 error page isn’t a bad thing. It prevents the code to be displayed in browsers and being read by hackers who are willing to steal passwords and blackmail webmasters.
500 error programmatically generated
A programmer has the ability to return a 500 error depending on some criteria. In this case, it is not an error. This is expected behavior from the server code the programmer. For example, the programmer wants to prevent bots to visit a page. So, the server code has been designed to return a 500 error message to bots and a 200 OK message to regular visitors using browsers.
HTTP fields aren’t valid
Some servers may bug when they receive HTTP fields from the requesters that aren’t valid to him. There are may too many HTTP fields or the contents of those HTTP fields may not suit the server.
A case study

In the example above, the server returned a 500 internal server error message. However, the page is accessible from a browser without any issue. We replicated the error by using the
$ curl -I http://www.maconnerie33bordeaux.fr/a/villenave-d-ornon-33
HTTP/1.1 500 Internal Server Error
Date: Wed, 20 Feb 2019 12:51:30 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Cache-Control: no-cache
Pragma: no-cache
Set-Cookie: c80bfa3dcc51838606150c76c2755d87=c6cf5ec39f60dcad587d2b9a382e301d; path=/
Connection: close
Content-Type: text/html; charset=utf-8
We found that the server returned a 500 error only when we requested the HTTP headers without the HTML content. As you can see the server features a script that returns a 500 error, if a client requests the HTTP headers of a page. By removing the parameter -I, it works because it returns the content of the page.