0

My header.php contains header information for all my pages, but for the error404.php page needs the nofollow meta data meta name='robots' content='noindex, nofollow.

I tried this in header.php

<?php if($page_id = 'error404') { echo "<meta name='robots' content='noindex, nofollow'>"; } return false; ?>

/*error404.php*/
define("PAGE", "Error404"); $page_id ='error404';

But I can't seem to get it to work. This code currently kills all the css on the index.php file.

I'm using .htaccess for handing error 404s.

.htaccess
# Send user to error404.php

ErrorDocument 404 /error404.php

Any help would be appreciated.

Sam
  • 7,252
  • 16
  • 46
  • 65
nickhiebertdev
  • 525
  • 1
  • 6
  • 21
  • Why do you need that? Having a 404 status will stop it being indexed, and why would you put links to places that shouldn't be indexed in your error document in the first place? – Quentin Jun 04 '14 at 20:17
  • I want it on the error404 page only @Quentin. – nickhiebertdev Jun 04 '14 at 20:18
  • Or is there a simpler way to handing this @Quentin? – nickhiebertdev Jun 04 '14 at 20:19
  • See my previous comment. The simpler way to handle things is to "Have a sensible 404 error page". – Quentin Jun 04 '14 at 20:19
  • I too question the need for this. However, @Quentin, what about 404 error pages that are part of a theme or template? The main menu links are part of the template... WordPress 404 error pages are part of the theme, links and all. – Sparky Jun 04 '14 at 20:24
  • Added htaccess info, I want to have the UI of my website showing for a error404 page. – nickhiebertdev Jun 04 '14 at 20:28
  • @Sparky - They are perfectly sensible 404 error pages. See my original comment. – Quentin Jun 04 '14 at 20:39
  • @Quentin, I'm not arguing with you. I'm simply wondering what makes WordPress 404 error pages (with their links) more "sensible". I guess the second part of your first comment is not that clear to me. What links are you talking about? – Sparky Jun 04 '14 at 21:00
  • @Quentin the website is a custom php/html5 website. Not using WordPress here. – nickhiebertdev Jun 04 '14 at 21:01
  • @nick... **just me**... **I** first mentioned WordPress _only_ as an example within my comment. We all know you're not using it and Quentin never said it. – Sparky Jun 04 '14 at 21:05
  • @Sparky — They are (a) pages with a 404 status code which (b) tell the user what went wrong and (c) have useful links (e.g. the standard site menu) for moving forward – Quentin Jun 04 '14 at 21:09
  • Ok @Quentin I'm done here. I already knew all that... just thought you were saying something else in your first comments... whatever, never mind. – Sparky Jun 04 '14 at 21:11

1 Answers1

-1

Just call

header("HTTP/1.0 404 Not Found");

before any output (echo, print, ...). You can still have custom error page, but there will be no indexing.

František Maša
  • 354
  • 1
  • 10
  • Will the .htaccess file still play a role in this if this is the first line of code in the error404.php file? – nickhiebertdev Jun 04 '14 at 20:39
  • Or is it simply not needed in this case? – nickhiebertdev Jun 04 '14 at 20:40
  • Specifying a status code using the PHP header function will override whatever the default is. The default for a 404 error document is 404, so this is entirely redundant and won't have any practical effect. – Quentin Jun 04 '14 at 20:44
  • @Quentin: I should explain it more. When you use PHP, you don't have to specify 404 error file in htaccess, but you can simply send 404 header using PHP and flush whatever content for Error page you want. 404 code itself will cause no indexing and you can still use same template. – František Maša Jun 27 '14 at 16:44
  • You can, but then you have to route the request to the PHP script that outputs that header via some means other then the default "file not found" Apache routing. Using your technique would pretty much demand rebuilding the site from the ground up using the front controller pattern. – Quentin Jun 27 '14 at 18:24