1

At present, my Drupal 7 website’s "Page not found" is 301 redirected to a custom 404 page.

However, I just checked the HTTP response code for a random URL and I noticed it 301 redirects to a custom "Page not found" page, but that page returns a 200 HTTP response code.

Shouldn't the page response header be 404?

If that's the case how do I fix the response code to 404 in Drupal 7?

  • Since there is a redirect, what you define "custom 404 page" cannot set a 404 HTTP code, since it is retrieved. The redirect changes the status, and the new page can just return 200 as code to tell the browser it was found. – kiamlaluno Oct 12 '18 at 15:10
  • Thanks kiamlaluno yes that's what happening to my drupal setup. How do I fix this then? This would be a mess for SEO purposes.. and indexing in google etc. – sd100 Oct 12 '18 at 15:12
  • You need to check what is causing the redirect, which is the main issue. If Drupal doesn't find a linked page, it returns a 404 error, so what you are describing is not the default behavior. – kiamlaluno Oct 12 '18 at 15:15
  • 1
    So I should just remove the redirect right? – sd100 Oct 12 '18 at 15:16
  • 1
    @sd100 yes. Remove the redirect and let Drupal handle the request. – AjitS Oct 12 '18 at 15:32
2

Instead of using a 301 redirect to your custom 404 page, just go to

Admin > Config > System > Site Information

/admin/config/system/site-information

Enter your new path into the 404 error page box, and click "Save configuration".

You might also want to try the CustomError module: https://www.drupal.org/project/customerror

|improve this answer|||||
  • can confirm, this is what I'm doing as well. But within the node that it redirects to when a 404 occures, I have it do <?php include DRUPAL_ROOT. '/widgets/includes/404.php'; ?> and within that 404.php page, it goes through a huge list of old URLs (from when the site was a Joomla thing) and forwards them to the new URL if there's a match. – Dan Mantyla Oct 12 '18 at 15:10
  • Assuming the OP set the redirect to the custom 404 page, this is how he should have done. From the question is not clear why the redirect is happening, though. – kiamlaluno Oct 12 '18 at 15:13
0

The default response of the not-found request is 404. Even if you use a custom page for 404 requests. The path to the page needs to set at admin/config/system/site-information for the
Default 404 (not found) page. Check the network tab for verifying the status of Type document.

|improve this answer|||||
  • I checked the site information page and the proper 404 pages node address is there.. what else should I check there? Thanks – sd100 Oct 12 '18 at 14:57
  • @sd100 Try checking for the status in the Network tab of the developer tools in your browser on a URL which does not exist, like /page/asdflksdf. The Type should be 404 for Type "document". – AjitS Oct 12 '18 at 15:00
  • Ok so done, and I see a 301 first, and a 404 below that in the "Status" column. – sd100 Oct 12 '18 at 15:03

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.