24

I have a site I recently upgraded. The old site had a calendar that created hundreds of pages, on the new site this has been replaced by an events page and those calendar URL's no longer exist. For months now I have been getting search engines pounding no longer existent pages like these ones.

For example:

page not found calendar-for-groups/2012-09-15/1093
page not found calendar-for-groups/2011-W09/77
page not found calendar-for-groups/2011-W27/77
page not found calendar-for-groups/2012-06-29/1093

How can I use htaccess to redirect any www.mywebsite.com/calendar-for-groups/* request to www.mywebsite.com/events?

Floern
  • 33,559
  • 24
  • 104
  • 119
Bryan Casler
  • 607
  • 3
  • 10
  • 20

2 Answers2

48

You could use the RedirectMatch directive of mod_alias:

RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/events

Or with mod_rewrite:

RewriteRule ^calendar-for-groups/ http://www.mywebsite.com/events [R=301,L]
Floern
  • 33,559
  • 24
  • 104
  • 119
  • I've tried all the suggestions so far and... `RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/events` worked like a charm. Thanks a million! – Bryan Casler Jul 30 '11 at 08:15
  • Hello @Floern Will this work in a buddypress site where I want to redirect all links going to any user but instead of the default tab, I want to choose a different tab. The current default tab leaves the body of the profile page blank. I want to redirect to the activity page. it is going to a profile page but doesn't choose the tab by default. – Rookie Recruits Apr 23 '20 at 16:55
10

You can do with a few rewrite rules:

RewriteEngine on
RewriteRule ^calendar-for-groups/(.*)   /events [R=301,L]
Marco Bizzarri
  • 371
  • 1
  • 5