Unusual issue with 404 not working on IIS
-
I am using the following generic bit of code in an IIS custom 404 page to make pretty permalinks work on IIS:
<?php
$path = substr($_SERVER[‘QUERY_STRING’], strpos($_SERVER[‘QUERY_STRING’], $_SERVER[‘SERVER_NAME’]));
$path = substr($path, strpos($path, ‘/’));
$_SERVER[‘REQUEST_URI’] = $path;
$_SERVER[‘PATH_INFO’] = $path;
include(‘index.php’);
?>Everything works fine. On the local copy of WordPress running on my computer, visiting a bad URL sends the user to the 404.php page in my theme. On the production copy, visiting a bad URL only brings up a blank page (it does return headers with a 404 HTTP status though). What I don’t get is that if I specify the HTTP status by adding a PHP header to my theme’s 404.php file, as long as the status is not 404, it works. Even if I add a 410 Gone status header it works.
Here are examples of the HTTP headers returned:
If I add <?php header(‘HTTP/1.1 410 Gone’); ?>:
HTTP/1.1 410 Gone
Cache-Control: no-cache, must-revalidate, max-age=0
Connection: close
Date: Wed, 01 Aug 2007 06:07:20 GMT
Pragma: no-cache
Content-Type: text/html; charset=UTF-8
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Wed, 01 Aug 2007 06:07:20 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: PHP/5.2.1
X-Pingback: https://trevorpowell.com/xmlrpc.php
X-Powered-By: ASP.NETWithout the header specified or with a 404 header:
HTTP/1.1 404 Not Found
Cache-Control: no-cache, must-revalidate, max-age=0
Connection: close
Date: Wed, 01 Aug 2007 06:16:20 GMT
Pragma: no-cache
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Wed, 01 Aug 2007 06:16:20 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: PHP/5.2.1
X-Pingback: https://trevorpowell.com/xmlrpc.php
X-Powered-By: ASP.NETI should also note that if I add an echo “\n”; line to the custom 404 page script, the contents of 404.php show up but then the page has a 200 OK HTTP status header.
This problem has proved hard to diagnose and any ideas would be appreciated. I have tried comparing my local phpinfo() to my host server’s phpinfo() but can’t see significant differences. Does anyone know what might be causing this?
- The topic ‘Unusual issue with 404 not working on IIS’ is closed to new replies.