Derek Hogue
Derek Hogue

Reputation: 4564

Rewriting old WordPress urls to new site's URL structure via .htaccess

Hey folks, I've migrated a site from WordPress to a new CMS, and I want to preserve the old URLs via a redirect.

The WordPress permalink structure was like so:

/2011/04/01/name-of-post

I've preserved the post slugs, so all I need to do is get rid of the date-based paths and redirect to my new directory structure:

/articles/view/name-of-post

My attempts thus far have looked like this (in my .htaccess file):

RewriteCond %{THE_REQUEST} /[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+) [NC]
RewriteRule ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+)$ /articles/view/$1 [L]

No luck yet. I tried %{PATH_INFO} in there as well, no dice.

Any help from those more versed in Apache rewrite rules than would be much appreciated.

Upvotes: 0

Views: 598

Answers (2)

anubhava
anubhava

Reputation: 784948

It can be handled in one simple RewriteRule like this:

RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+)$ /articles/view/$1 [L]

Upvotes: 0

BillThor
BillThor

Reputation: 7576

Something like this should do.

RedirectMatch permanent ^/20../../../(.*)$           /articles/view/$1

Upvotes: 1

Related Questions