Advertisement
dprophit

AskApache custom HTTPD ErrorDocument

Jun 12th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //created by AskApache.com for http://www.askapache.com/seo/404-google-wordpress-plugin.html
  3.  
  4. $ASKAPACHE_STATUS_CODES = array(
  5. '400'=>array('Bad Request', 'Your browser sent a request that this server could not understand.'),
  6. '401'=>array('Authorization Required', 'This server could not verify that you are authorized to access the document requested.'),
  7. '402'=>array('Payment Required', 'INTERROR'),
  8. '403'=>array('Forbidden', 'You don\'t have permission to access THEREQUESTURI on this server.'),
  9. '404'=>array('Not Found', 'We couldn\'t find <acronym title=\"THEREQUESTURI\">that uri</acronym> on our server, though it\'s most certainly not your fault.'),
  10. '405'=>array('Method Not Allowed', 'The requested method THEREQMETH is not allowed for the URL THEREQUESTURI.'),
  11. '406'=>array('Not Acceptable', 'An appropriate representation of the requested resource THEREQUESTURI could not be found on this server.'),
  12. '407'=>array('Proxy Authentication Required', 'This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn\'t understand how to supply the credentials required.'),
  13. '408'=>array('Request Time-out', 'Server timeout waiting for the HTTP request from the client.'),
  14. '409'=>array('Conflict', 'INTERROR'),
  15. '410'=>array('Gone', 'The requested resourceTHEREQUESTURIis no longer available on this server and there is no forwarding address. Please remove all references to this resource.'),
  16. '411'=>array('Length Required', 'A request of the requested method GET requires a valid Content-length.'),
  17. '412'=>array('Precondition Failed', 'The precondition on the request for the URL THEREQUESTURI evaluated to false.'),
  18. '413'=>array('Request Entity Too Large', 'The requested resource THEREQUESTURI does not allow request data with GET requests, or the amount of data provided in the request exceeds the capacity limit.'),
  19. '414'=>array('Request-URI Too Large', 'The requested URL\'s length exceeds the capacity limit for this server.'),
  20. '415'=>array('Unsupported Media Type', 'The supplied request data is not in a format acceptable for processing by this resource.'),
  21. '416'=>array('Requested Range Not Satisfiable', 'The Web server (running the Web site) thinks that the HTTP data stream sent by the client (e.g. your Web browser or our CheckUpDown robot) contains a \'Range\' request which specifies a range of bytes which can not be satisfied - because the resource being accessed does not cover this byte range. For example if the resource - an image file for example - has 1000 bytes and the Range requested is 500-1500, then it can not be satisfied.'),
  22. '417'=>array('Expectation Failed', 'The expectation given in the Expect request-header field could not be met by this server. The client sent <code>Expect:</code>'),
  23. '422'=>array('Unprocessable Entity', 'The server understands the media type of the request entity, but was unable to process the contained instructions.'),
  24. '423'=>array('Locked', 'The requested resource is currently locked. The lock must be released or proper identification given before the method can be applied.'),
  25. '424'=>array('Failed Dependency', 'The method could not be performed on the resource because the requested action depended on another action and that other action failed.'),
  26. '425'=>array('No code', 'INTERROR'),
  27. '426'=>array('Upgrade Required', 'The requested resource can only be retrieved using SSL. The server is willing to upgrade the current connection to SSL, but your client doesn\'t support it. Either upgrade your client, or try requesting the page using https:// protocol'),
  28. '500'=>array('Internal Server Error', 'INTERROR'),
  29. '501'=>array('Method Not Implemented', 'GET to THEREQUESTURI not supported.'),
  30. '502'=>array('Bad Gateway', 'The proxy server received an invalid response from an upstream server.'),
  31. '503'=>array('Service Temporarily Unavailable', 'The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.'),
  32. '504'=>array('Gateway Time-out', 'The proxy server did not receive a timely response from the upstream server.'),
  33. '505'=>array('HTTP Version Not Supported', 'INTERROR'),
  34. '506'=>array('Variant Also Negotiates', 'A variant for the requested resource <code>THEREQUESTURI</code> is itself a negotiable resource. This indicates a configuration error.'),
  35. '507'=>array('Insufficient Storage', 'The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. There is insufficient free space left in your storage allocation.'),
  36. '510'=>array('Not Extended', 'A mandatory extension policy in the request is not accepted by the server for this resource.'));
  37.  
  38. function aa_print_html ($AA_C){
  39.     global $AA_REQUEST_METHOD, $AA_REASON_PHRASE, $AA_MESSAGE;
  40.  
  41.     if($AA_C == '400'||$AA_C == '403'||$AA_C == '405'||$AA_C[0] == '5'){
  42.         @header("Connection: close",1);
  43.  
  44.         if($AA_C=='405')@header('Allow: GET,HEAD,POST,OPTIONS,TRACE');
  45.  
  46.         echo "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">n<html><head>";
  47.         echo "<title>$AA_C $AA_REASON_PHRASE</title>";
  48.         echo "<h1>$AA_REASON_PHRASE</h1>n<p>$AA_MESSAGE<br />n</p>n</body></html>";
  49.         return true;
  50.     } else return false;
  51. }
  52.  
  53. if(!isset($_REQUEST['error']))  $AA_STATUS_CODE = '404';
  54. else  $AA_STATUS_CODE = $_REQUEST['error'];
  55. if(isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS']!='200') $AA_STATUS_CODE = $_SERVER['REDIRECT_STATUS'];
  56.  
  57. $AA_REQUEST_METHOD = $_SERVER['REQUEST_METHOD'];
  58. $AA_THE_REQUEST = htmlentities(strip_tags($_SERVER['REQUEST_URI']));
  59. $AA_REASON_PHRASE = $ASKAPACHE_STATUS_CODES[$AA_STATUS_CODE][0];
  60. $AA_M_SR=array(array('INTERROR','THEREQUESTURI','THEREQMETH'),array('The server encountered an internal error or misconfiguration and was unable to complete your request.',$AA_THE_REQUEST,$AA_REQUEST_METHOD));
  61. $AA_MESSAGE  = str_replace($AA_M_SR[0],$AA_M_SR[1],$ASKAPACHE_STATUS_CODES[$AA_STATUS_CODE][1]);
  62.  
  63. ob_start();
  64. @header("HTTP/1.1 $AA_STATUS_CODE $AA_REASON_PHRASE",1);
  65. @header("Status: $AA_STATUS_CODE $AA_REASON_PHRASE",1);
  66.  
  67. if(!aa_print_html($AA_STATUS_CODE)){
  68.     ?>
  69.     <?php get_header();?>
  70.     <div id="content">
  71.     <div class="post">
  72.     <h1><?php _e("$AA_STATUS_CODE $AA_REASON_PHRASE"); ?></h1>
  73.     <?php if(function_exists('aa_google_404')) aa_google_404(); ?>
  74.     </div>
  75.     </div>
  76.     <?php get_sidebar(); ?>
  77.     <?php get_footer(); ?>
  78. <?php }
  79. exit;
  80. exit();
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement