My .htaccess

ErrorDocument 404 http://www.mywebsite.com/error_404.php

My error_404.php header

<?php header("HTTP/1.1 404 Not Found");?>

Redirection works well but it seems like this configuration is not accepted by Google, This is a random page Google Webmaster Fetch

HTTP/1.1 302 Found
Date: Sun, 13 Dec 2015 11:19:57 GMT
Server: Apache
Location: http://www.askcyan.com/error_404.php
Content-Length: 220
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

<title>302 Found</title>
<p>The document has moved <a href="http://www.mywebsite.com/error_404.php">here</a>.</p>
  • 1
    "Redirection works well" - that's the thing... for an error document you don't want it to "redirect". Ideally you want it to internally rewrite the request. If it redirects then the first status code returned is a 3xx, not a 404. – MrWhite Dec 13 '15 at 23:13
  • It can pay off to not always reference the same domain name when referring to URLs on your own server, especially when dealing with URLs in anchor tags. It will make your code smaller and thus less server bandwidth and financial expenses will be required in the long run. – Mike Dec 14 '15 at 4:22

You want:

ErrorDocument 404 /error_404.php

Don't put the absolute URL in there - that's what's causing the redirect. Also, you don't need to set the 404 header through PHP - Apache will do that for you.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.