3

My website had some URLs automatically added to it by WordPress. They got indexed in Google. Now I want those URLs to show as "410 Gone".

For example:

  • /contact/
  • /about-us/

These pages are not on the website anymore. The new website is created with PHP.

How do I make them 410 error pages or otherwise make Google drop them from the search index?

3
  • If these produce a 404 now, then you can just live with this. These pages cannot rank for anything being gone so I do not believe this will be a problem. If Google gets a 404, the pages (or lack thereof) will drop in the SERPs out of sight. Google will retry these for a while before it decides the page is really gone. If there are no links, then the 404 becomes equivalent to a 410 ultimately. I firmly believe that the simplest solution is often the best. Cheers!!
    – closetnoc
    Commented Nov 2, 2016 at 0:29
  • Please remember to accept the answer if this satisfies your question.
    – Itai
    Commented Oct 17, 2017 at 23:12
  • By my expirience you should just wait a while and google will remove it if doesnt exist,i tried with .htaccess and set pages as 410 and i got nothing from that.We cant speed up removal process,its slow as snail,really doesnt matter does we set it 404 or 410 or nothing.Solution is - delete and wait. Commented Feb 18 at 15:44

2 Answers 2

5

Directly in PHP, all you need is to output the 410 header:

header( "HTTP/1.1 410 Gone" );

For safety, it is recommended to call exit() after.

Suppose you have a handful of pages, you can either just make one file for each or modify the .htaccess using a RewriteRule that maps all gone pages to one PHP file which sends the 410 status as shown above.

Technically, you do not need the PHP at all since the .htaccess can send the status based rules which you set such as:

RewriteRule ^contact/ - [L,R=410]
RewriteRule ^about/ - [L,R=410]

For a large number of such pages, I usually encode the logic in a custom error page written in PHP. It is called for when a file is not found and it can perform a lookup to determine if it should return the 410 header or not (and do other things as needed, including collecting statistics on how often these pages get accessed).

1
1

When Google receves 404 not found errors for a page repeatedly it treats it as a 410 gone and so removes them from the index. The first time or two that Google gets a 404 it won't remove the page from the index as it treats it as a possible temporary fault.

Strictly speaking you don't have to mark gone pages as 410's but if you do wish to then all you have to do is go into your .htaccess file in the site root and add the following line...

Redirect 410 /foo/bar/demo.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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