This website uses cookies to improve your experience and deliver relevant information.

on Wednesday, 06 September 2017

How to properly kill a URL with a 410 status code

Sometimes you will have the need to properly kill a page on your website - perhaps a member of staff has left and you want to remove their profile, or you're taking down a section that is no longer relevant.  A 410 status code tells visitors that the page has been removed and will not be returning - and it is the 'correct' way to remove resources.

Creating a 410 entry for your htaccess file is pretty simple really, there are a few ways of achieving it.  If you don't have mod_rewrite enabled, you'll need to use redirect rules. If you have mod_rewrite enabled then you can gain a bit more flexibility using rewrite rules.

Using the 410 redirect

A simple redirect rule would be something like this:

redirect 410 /subfolder_or_not/titleurl.html

This will result in the browser receiving a 410 status code when accessing yoursite.com/subfolder_or_not/titleurl.html, which effectively means 'this is gone and it's not coming back'.

Using rewrite rules

With rewrite rules we can do a bit more.

Simple 410 rewrite

RewriteEngine On 
RewriteBase / RewriteRule ^example-html-filename-1\.html$ - [G,NC]

Note: If you're already using mod_rewrite on your website, for example using search engine optimised URLs, it is likely that the first two lines are already set in your htaccess file.

The [G] denotes 'Gone' (410) and the [NC] denotes that it is case insensitive.

Rewrite entire folder/category

If we need to do something a bit more complex, we can use regular expressions - for example, let's presume we wanted to kill off the entire directory /blog on our site.  To do this we could use a rewrite rule:


RewriteRule ^blog/ - [G, NC]

In the rule above, anything on your website in the /blog folder would return a status of 'gone' (another way of saying 410 error). 

Rewrite based on query strings

Another use case might be redirecting everything with ?my-keyword-string in the URL:

RewriteCond %{QUERY_STRING} my-keyword-string
RewriteRule .* - [G,NC]

With great power comes great responsibility - always check that you are using the correct syntax for rewrite rules, and make sure the outcome is as you expect on both the pages you seek to kill off as well as other areas of the site, as it's easy to make a mistake and accidentally kill off more than you intend!

 

Need Marketing or SEO support for your project? Work with the experts today!

Virya Group provides a range of solutions to your technology needs