views:

131

answers:

0

In my wordpress site, I have a specific condition that triggers a 404 in which I want to handle as a "404 exception" (< there's probably a better term I could use but hopefully it conveys the spirit of what I'm trying to do :)

For example, the page mysite.com/site-map does not exist in my site, however, I have a link called "Site Map" that calls mysite.com/site-map and I want to insure that requests on this link are not reported as 404.

Here is the code I've placed at the top of 404.php

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
$URL = curPageURL();
if(substr($URL, -1 * strlen("/site-map")) == "/site-map") {
    header("HTTP/1.1 201 OK");
}

Using the Firefox plugin, "Live HTTP Headers" I get the following response. Is this a true 201 OK or should I send the header in a different manner? I'm trying to simply resolve the header as a valid response and not a 404.

GET /mysite/site-map HTTP/1.1
Host: localhost
If-Modified-Since: Thu, 04 Mar 2010 13:50:06 GMT

HTTP/1.1 201 OK
Date: Thu, 04 Mar 2010 13:58:26 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Thu, 04 Mar 2010 13:58:26 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Content-Length: 5460
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8