Search code examples
url-rewritinghttp-status-code-404google-plus-one

Handling 404's with non-redirecting pages that can't be "+1'd


I am using an .htaccess custom error page "error.php". Problem is, all it does is just redirect them.

I would like for my 404 to display the requested URL in the address bar, as if the user was never redirected.

Here are a few model examples:

http://us.battle.net/wow/en/22222222222222222222

http://en.wikipedia.org/wiki/222222222222222222222

Are these pages simply using a URL rewriter that is in actuality something like "domain.com/index.php?page=2222222222222222222222" ? If so, are they just printing out text without indicating that it is a 404 page without marking it as an error page somehow?

They have to be sending something in the header. I have a Chrome Extension for the +1 button, and when I go to the listed pages, it gives me an error saying "Cannot +1 this page."

Does anyone have any idea what "flag" is being used here?


Solution

  • Yes, you can send HTTP status codes using the pre-processor which determines that the page doesn't exist. For example, in PHP you would use this:

    header('HTTP/1.1 404 Page Not Found');
    

    This would send the 404 header along with the custom 404 page you want to display. You can do this with any HTTP status code, even make up your own (though they probably won't be recognized).

    header('HTTP/1.1 418 I'm a Teapot');
    

    If you use Apache's ErrorDocument definition in your .htaccess file, it should maintain the error code so long as you do not modify the headers with the page defined (such as running a PHP file) or redirect to a new page. Using plain text and/or (possibly) a HTML file would preserve the 404 header. I have never tested it with an HTML file.