Reputation: 1718
In apache I'd like to return 404 errors whenever I get a 500 error.
Its a very strange use case, I know, but I'm wondering if its possible.
I found this
http://www.4webhelp.net/tutorials/misc/errors.php
Which leads me to believe you can change what happens on the different errors. Something like this would be great
ErrorDocument 404 /cgi-bin/error404.cgi
ErrorDocument 500 /cgi-bin/error404.cgi
As suggested by the article, but I don't seem to have error404.cgi on my Ubuntu installation. Any idea where I can get it, or an alternative solution?
Upvotes: 3
Views: 2120
Reputation: 327
You have to create error404.cgi. Go to /usr/lib/cgi-bin and then create a file called error404.cgi it should be either Perl (default) or if Python is enabled, you can use either. If you do not know either Python or Perl, heres a basic Perl script which should work for you: (You can download the script from my website at cwarren.uuuq.com/downloads/perl/404.pl
#!/usr/bin/perl use strict; print "<html>"; print "<head>"; print "<title>404 ERROR!</title>"; print "</head>"; print "<body>"; print "<h1>Sorry for the broken link, but this page is not here!</h1>"; print "<br><br>"; print "<a href=\"javascript:history.go(-1)\">Click here to go back to the previous page.</a>"; exit(0);
Another option would be to change the link to /var/www/404.html or something.
Upvotes: 0
Reputation: 13916
I know this doesn't answer your question but are you sure that you really want to do this? a 500 error and 404 are very different things meant to be used for different purposes. You are telling a user that the url that they have is wrong when in fact it is what is more than likely a temporary problem with your application/server. Why would you rather do this than to tell the user there is a temporary problem and they should try again later on? Or in other words, why not just have a custom 500 error page?
Upvotes: 1