downtomike
downtomike

Reputation: 94

Regex htaccess remove multiple URL segments

I had a Wordpress blog where the individual post URLs were set up like this: http://blogname.com/knowledge-communities/2013/01/blog-title

I recently refreshed the site and they are now set to this: http://blogname.com/blog-title

So if a user finds a link to an old blog post(through Twitter or other social media), I want to redirect them to the new URL structure by removing the 'knowledge-communities' segment and the date segments(2013/01).

I have this so far which is removing the 'knowledge-communities' segment, but I can't find a way to remove the date segments- /2013/01. RewriteRule ^knowledge\-communities/(.*) /$1 [R=301,L]

Any help is appreciated.

Upvotes: 0

Views: 355

Answers (2)

foundry
foundry

Reputation: 31745

  /\d{4}/\d{2} 

will pick out your date string

Upvotes: 0

Pilou
Pilou

Reputation: 1478

You can modify your regex to catch the item after two groups of digits :

RewriteRule ^knowledge\-communities/[0-9]+/[0-9]+/(.*) /$1 [R=301,L]

Upvotes: 1

Related Questions