Mobile app version of vmapp.org
Login or Join
LarsenBagley505

: How do I create 410 errors for no longer existing pages on my PHP website? My website had some URLs automatically added to it by WordPress. They got indexed in Google. Now I want those

@LarsenBagley505

Posted in: #410Gone

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley505

2 Comments

Sorted by latest first Latest Oldest Best

 

@Welton855

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).

10% popularity Vote Up Vote Down


 

@Berumen354

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme