Creating the Difference

Prevent Google from indexing past Events

Posted on: 15-05-2019 Last modified: 16-08-2020
Categories: htaccess, Snippets Tags: , , ,

What happens if you delete a past event?

Of course you want Google to index your website and its Events Manager events! ;-)
But you do not want Google to keep showing past events in the search results, right?

The simplest solution to “remove” your past event form Google, is by simply deleting it from your WordPress Dashboard. But… then you will automatically lose all booking info, because EM immediately cleans up the database. We don’t want that!

Also, deleting an event (or page or post for that matter) will not tell Google that it’s gone. So Google will still try to find it when the Googlebot crawls your wesbite. Since the page cannot be found, it will result in a 404-error (“Page not found”). Google does not like 404’s. Actually, it will punish websites that have lots of missing pages by lowering them in the search results. Their policy is something among the lines of “If you don’t maintain the website properly, why should we reward you?” A bit harsh, yes, but logically explainable.

Yoast SEO warns you when deleting a post.

If you’re using the Yoast SEO plugin and ever deleted a post/page or event, you have probably seen the (over time extremely annoying) Admin Notice to upgrade Yoast. That upgrade contains (among others) a feature to semi-automatically create a redirect for the deleted post, so Google and your visitors will not get a 404-error.
But again, that is if you delete a post.

We don’t want to index past event, but keep the booking info!

Of course you do! :-)

So, technically what you want to achieve, is to keep the WordPress Admin unchanged – keeping the event history in tact, but on the front-end, you do not wat search engines to index past events, nor have human visitors see old info.

So, we will manually create a redirect for the front-end only.

Step 1: Make sure your event slugs are compatible.

To sort of automate this process, you will need to make sure that your event slugs always contain the event date as Y-m-d, /events/my-event-2019-02-25 would be perfect. The year and month have to be together, because that will allow us to target a whole month at once. In this example, I am assuming your Events List Page is /events/.

Step 2: Add a single line to .htaccess, each month.

IMPORTANT: If you are not comfortable with editing the .htaccess file, please don’t proceed! One wrong character in your .htaccess will break your website.

To redirect events of the past month (April for example), you need to add (after April has ended) this line to your .htaccess file: RedirectMatch 301 ^/events/(.*)-2019-04-(.*)$ /events/

A 301 Redirect means:
“This URL has been Permanently Moved”, which tells search engines to delete the old URL from their index.

The whole line means:
“Redirect any URL in /events/ containing ‘-2019-04-‘ to /events/” will now redirect to

Step 3: Do some cleaning, once a year.

After twelve months, you will have twelve lines for redirecting past events of that year. To keep your .htaccess file nice and tidy, celebrate New Year’s Day with your very own “Clean-Up .htaccess Party”. :-P

Replace the 12 monthly lines (-2019-05-) with one for the whole past year:
RedirectMatch 301 ^/events/(.*)-2019-(.*)$ /events/

⇐ Previous
Next ⇒