Lukas Pleva
Lukas Pleva

Reputation: 381

Wordpress permalink redirect rule

Running into a little bit of an issue with Wordpress permalink redirects that I was hoping I could get some help with.

Previously, I utilized the following permalink structure for my blog posts:

/blog/%year%/%monthnum%/ %day%/%postname%/

I've recently changed it to:

/blog/%postname%/

Problem is, none of my old links which were structured using the old format now work!

I know it's possible to write a general .htaccess 301 redirect rule, but besides knowing that it's possible, I don't actually know how to do it.

Any tips?

Upvotes: 0

Views: 209

Answers (2)

Just Thomas Misund
Just Thomas Misund

Reputation: 539

WordPress should recognize the old permalinks by default. You should try hitting Dashboard > Settings > Permalinks > Save changes one more time.

In case it doesn't work, the regex your're asking for would be something like this, removing 4 digits, a slash, 2 more digits, another slash, yet 2 more digits and one last slash from the URL:

RewriteEngine On
RewriteRule ^blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$ http://example.com/blog/$1

Upvotes: 0

WebChemist
WebChemist

Reputation: 4411

This will strip out any number/number/number/ formatting from the url

RewriteRule ^blog/([0-9]+/){3}(.*) /blog/$2 [R=301,L]

Upvotes: 1

Related Questions