rewrite rule wordpress custom url

I had an old website programmed for me and now i have migrated it to wordpress, but many websites still have links to the old urls and i want to redirect them to WordPress because there are having a 404 response.

the old structure was: http://www.website.com/news/2013/june/01/slug-slug-slug-slug
the new in wordpress: http://www.website.com/news/2013/06/01/slug-slug-slug

Read More

Note that i only need to change:

january -> 01
february -> 02
march -> 03
april -> 04
may -> 05
june -> 06
july -> 07
august ->08
september -> 09
october -> 10
november -> 11
december -> 12

Do i have to include something in wordpress’ .htaccess or in the rewrite.php file? I heve been thinking that i only need to change the %monthday% variable from numeric to string… but if i update wordpress i probably need to change it again.

Related posts

Leave a Reply

2 comments

  1. If you want to use mod_rewrite, you can do this with 12 rules. I am not familiar with wordpress itself and I don’t know if there is an ‘easy’ way via the config of WordPress itself. Add the following rules above the rule that sends all requests to WordPress’ index.php file:

    RewriteRule ^news/([^/]+)/january/([^/]+)/(.*)$ /news/$1/01/$2/$3 [R,L]
    RewriteRule ^news/([^/]+)/february/([^/]+)/(.*)$ /news/$1/02/$2/$3 [R,L]
    RewriteRule ^news/([^/]+)/march/([^/]+)/(.*)$ /news/$1/03/$2/$3 [R,L]
    #etc...
    

    As always, see the documentation for information about the syntax being used.

  2. There will be 12 rules like this so you can have something like this:

    RewriteRule ^(news/[^/]+)/january/([^/]+/.+)$ $1/01/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/february/([^/]+/.+)$ $1/02/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/march/([^/]+/.+)$ $1/03/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/april/([^/]+/.+)$ $1/04/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/may/([^/]+/.+)$ $1/05/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/june/([^/]+/.+)$ $1/06/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/july/([^/]+/.+)$ $1/07/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/august/([^/]+/.+)$ $1/08/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/september/([^/]+/.+)$ $1/09/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/october/([^/]+/.+)$ $1/10/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/november/([^/]+/.+)$ $1/11/$2 [L,R=301,NC]
    RewriteRule ^(news/[^/]+)/december/([^/]+/.+)$ $1/12/$2 [L,R=301,NC]
    

    Also make sure to have these rules on top, before any other rewrite rules.