How to Update Your WordPress Permalinks Without Causing Link Rot

If you are chang­ing your perma­links struc­ture dif­fer­ent­ly than what is described below (e.g., going from name-based perma­links back to name and date-based perma­links), there is a Word­Press plu­g­in that can take care of you. If all you want to do is change from name and date-based perma­links to name-based perma­links, the method described below should be a bit faster, as the redi­rect is han­dled at the serv­er lev­el rather than at the PHP level.

This is a fol­low-up to my ear­li­er post Seam­less Perma­link Updat­ing. The prob­lem I faced was that I want­ed to change my Word­Press perma­link set­tings from being date and name based to some­thing which was sim­ply name based.

Why did I want to do this?

  1. Perma­links would be short­er; remov­ing the date infor­ma­tion results in URIs which are eleven char­ac­ters shorter.
  2. Perma­links would not only be more read­able, they would be more mean­ing­ful to humans; dates aren’t as impor­tant as the con­tent the page itself con­tains. If pre­sent­ed with a list of perma­links from this site, users should have a good idea of what they’ll get when they click them. There’s no rea­son to mud­dy those waters by inject­ing date infor­ma­tion into the mix, dilut­ing the impact of the domain and post slug.
  3. The con­tent part of the perma­links (domain name + post slug) would car­ry more impact in var­i­ous search engines, with­out date infor­ma­tion (that may or may not be rec­og­nized as dates by search engine algo­rithms) dilut­ing the val­ue of what­ev­er key­words may be present.
  4. Yes, this is a blog, and yes infor­ma­tion is post­ed chrono­log­i­cal­ly; how­ev­er, this isn’t a nov­el, and the mate­r­i­al here need not be read in a chrono­log­i­cal man­ner in order to under­stand it. Hav­ing date-based perma­links cre­ates the illu­sion that the date the mate­r­i­al was post­ed is more impor­tant than it real­ly is. Besides, posts are dis­played with the date any­way; why give it to the user twice when I’m bet­ting the date includ­ed with the post is glanced over by most users.

Great rea­sons, I think, which should suf­fice for now. So I want­ed to change my perma­links; what did I do about it?

Word­Press makes the process ridicu­lous­ly simple.

  1. Vis­it the Perma­links page of the admin­is­tra­tion pan­el (/wp-admin/options-permalink.php).
  2. Select the but­ton labeled “Cus­tom, spec­i­fy below.”
  3. In the box labeled “Cus­tom struc­ture,” enter the text /%postname%/
  4. Sub­mit the change via the “Update Perma­link Struc­ture »” button.
  5. Vis­it your site and ver­i­fy that posts are not being giv­en perma­links in the style Beau­ti­ful, no?

Like I said, ridicu­lous­ly easy!

But con­sid­er: What hap­pens to all the links out there on the Inter­net to your blog which make use of the pre­vi­ous style of perma­links? Try it out for your­self; find an old perma­link in your browser’s his­to­ry that still makes use of “Date and name based” perma­links and vis­it it.

404! You broke the Inter­net! File not found! It’s the end of the world as you know it!

But don’t wor­ry, you can feel fine about it because I have a solu­tion, pro­vid­ed that you are using Apache as your serv­er envi­ron­ment (chances are, you are) and mod_alias is enabled (I’m unsure how com­mon it is). We’ll be fix­ing our prob­lem using the RedirectMatch direc­tive of mod_alias.

  1. Down­load your blog’s pri­ma­ry .htaccess file; most like­ly, it’ll be in the same direc­to­ry as your blog’s wp-config.php file.
  2. Open it up, and find Word­Press’ perma­links code. If you’ve nev­er edit­ed your .htaccess file before, it will most like­ly be the only code present. The code looks like this, give or take a line break:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
  3. Before that Word­Press code, you’ll want to add one of the following: 
    • If your Word­Press is installed in your domain’s root direc­to­ry (e.g.,, add this code, adjust­ing to your prop­er domain name:

      RedirectMatch permanent ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+)$1
    • If your Word­Press is installed in a sub­di­rec­to­ry of your domain (e.g.,, add this code, adjust­ing to your prop­er domain name and directory:

      RedirectMatch permanent /blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+)$1
  4. Save & upload the .htaccess file, and revis­it one of your old­er date-based perma­links. If all went accord­ing to plan, you should be seam­less­ly redi­rect­ed to your new name-based permalinks.

That’s all there is to it! If any­one can pro­vide a bet­ter means, I’m open to it, but I’ve test­ed this out, and it works exact­ly as I want it to — posts work, paged posts work, pages work, and so on. I can’t promise this won’t break any Word­Press plu­g­ins, so be pre­pared to give up this method (which is as easy as delet­ing what­ev­er you add to .htaccess and switch­ing your perma­link struc­ture back).

For the curi­ous, this is what the code above does, piece by piece:

Begins the call to Apache’s mod_alias module.
Sends the client (i.e., the user, whether human or robot) instruc­tion that this redi­rect is a per­ma­nent redi­rect and that the old address is invalid and should be from now on replaced with the new.
The address which we’re try­ing to match begins with a four-dig­it year stamp, so we first look for a slash fol­lowed by four numbers.
The address will next have a two-dig­it month stamp, so we check for anoth­er slash fol­lowed by two numbers.
The address will next have a two-dig­it day stamp, so we check for yet anoth­er slash fol­lowed again by two numbers.
The address will then have the post slug, which can con­sist of a vari­ety of low­er­case let­ters, num­bers, and dash­es. So we look for any num­ber of those. A post slug may include addi­tion­al infor­ma­tion after it, such as a page num­ber on paged posts, so we include any num­ber of slash­es in our search as well. It’s enclosed in paren­the­ses so we can cap­ture that data and use it in the next section.$1
This is the loca­tion of where we want to redi­rect to. The $1 at the end will be replaced by what­ev­er was matched by the code in paren­the­ses in the pre­vi­ous statement.

Edit: Whoops! Using the above RedirectMatch code pre­vent­ed view­ing of day archives (e.g., /2008/01/01/); swap­ping the aster­isk (*) out for a plus sign (+) resolved the issue and allows day archives to be viewed. The code above has been corrected.

58 thoughts on “How to Update Your WordPress Permalinks Without Causing Link Rot”

  1. Excel­lent post, Rick.

    I am seri­ous­ly (re-)considering remov­ing the date por­tion of my perma­links. One of the last (log­i­cal) rea­sons I can think of to avoid this change involves the abil­i­ty to dis­play posts via year, month, and day views. To what extent are the archive pages work­ing with this method in place? And final­ly, have you noticed any con­flicts with plu­g­ins, etc.?

    Also, you may be amused to know that in an attempt to solve this mys­tery, I had dis­cov­ered the same htac­cess tech­nique and even wrote a (remark­ably sim­i­lar) arti­cle explain­ing the imple­men­ta­tion process.. I was ready to roll with it, but by the time I had fin­ished my work week and returned to the com­put­er, you had already devised a solu­tion and pub­lished an arti­cle — doh!

  2. Looks like there’s actu­al­ly a Word­Press plu­g­in that allows for redi­rect­ing old perma­links to new ones. I added a note at the begin­ning of the post above with a link to it.

  3. Chris — Saw that linked to ear­li­er from Weblog Tools Col­lec­tion. I only read the excerpt­ed quote then, but fol­lowed your link and read it in full.

    He’s absolute­ly right when he implies that perma­link design is very site specific.

    How­ev­er, it would be inter­est­ing to tin­ker around and see how much pull a perma­link has on how Google index­es — for instance, if the above post had a perma­link which ref­er­enced Brit­ney Spears, Paris Hilton, and so on, how long would it take for traf­fic to show up look­ing for that kin­da stuff, if at all?

    It’d make for an inter­est­ing exper­i­ment, I think!

  4. Lol, I’ll leave the tin­ker­ing and exper­i­ment­ing to you :-) I had a post and poll about cred­it cards a while back, and I noticed a big change in amount and type of spam…

  5. Great post, worked like a charm for con­vert­ing my word­press perma­links from the default ?p=\d+ for­mat to the /%postname%/ for­mat. Thanks!

  6. ryan woodrum & amy — I’m glad both of you were able to ben­e­fit from this guide! If you have any prob­lems relat­ed to perma­links as a result of fol­low­ing any of the above advice, just drop a com­ment, and I’ll do my best to sort out your issue(s)!

  7. We want to thank you for this sim­ple, easy-to-fol­low instruc­tions on the redi­rec­tion. We’ve been try­ing to do this for weeks now and, because of your post, I just fixed it in 2 min­utes! We’re book­mark­ing this!! Thanks so much.

    Amy and Jon­ny —

  8. Could you post the con­tents of the mod­i­fied .htac­cess you are using? You can paste it onto this site [ ] and give me the link to the result­ing code page.

    A Serv­er Con­fig­u­ra­tion prob­lem could be caused by any num­ber of things, unfor­tu­nate­ly, but I’ll take a look for ya!

  9. Hi, I tried the htac­cess rule you sug­gest, of course I change to my web­site, but all I get is an error page about serv­er con­fig­u­ra­tion and addi­tion­al 500 error. My WP instal­la­tion is in my domain’s root. Any Idea?

    Thanks you :-)

  10. James: Try adding the lines I added — they should be highlighted:

    If the serv­er error goes away and the redi­rect­ing does not work, then the cause is because Mod_Alias is not con­fig­ured on your serv­er and a solu­tion using Mod_Rewrite will need to be used.

    For more infor­ma­tion on Mod_Alias:

    Jeff over at Per­ish­able Press presents the Mod_Rewrite rules if you want to try them out.

  11. That was fast :-)
    Right now I set up a cpan­el redi­rect but that’s for a cou­ple of old posts. I haven’t actu­al­ly change the perma­link struc­ture in WP, I just change some posts date and since then I’m see­ing few errors caused by vis­i­tors com­ing from search engines.
    Any­way, here’s my htac­cess

  12. Thank you so much for the infor­ma­tion. The plu­g­in that many peo­ple use does­n’t work for con­vert­ing from default pages, but luck­i­ly I stum­bled upon your solu­tion, and it works per­fect­ly. Thanks again for your help­ful article.

  13. Hi Rick,

    I had the month and name struc­ture for the perma­links of my blog. Recent­ly, due to oth­er prob­lems, I delet­ed the whole WP instal­la­tion and did a new clean one, then I re-import­ed all my posts and now I’ve set direct­ly the perma­link struc­ture to /%postname%/.

    So now I’ve the prob­lem that in the old blogs I’ve still inter­nal links with the old “month and name” perma­link struc­ture. I thought to fix the prob­lem with your redi­rec­tion, but it does­n’t work: I get an 404 error.

    Take a look at my .htac­cess file and please help me to find where I fail.

    Thanks in advance & ciao


  14. Alexan­der — Strate­gieVin­cen­ti: Trou­bleshoot­ing HTAc­cess prob­lems is not some­thing at which I’m at all skilled. If my solu­tion above does­n’t work for you, try out this one from a friend of mine. We were both work­ing at solv­ing the prob­lem of short­en­ing perma­links at the same time. I’m pret­ty sure his solu­tion will work in a wider vari­ety of cas­es as it uses the same tech­nol­o­gy as Word­Press perma­links. My solu­tion uses a dif­fer­ent Apache mod­ule than the Word­Press rewrite rules do; it may not be present or enabled on all systems.

  15. Hi Rick,

    very inter­est­ing article.

    Over the week­end, I actu­aly did a dou­ble change. I switched from a win­dows based serv­er to the Apache ver­sion, to get rid of the stu­pid index.php

    And on top of that, I want­ed to get rid of the day in the url, but keep the year and month.

    To do all this, I used the tool that you men­tion and that may have a secu­ri­ty breach. So I’m cer­tain­ly will­ing to give your sug­ges­tion a go, but how would that string look like in my case?

    Orig­i­nal url:

    Cur­rent URL:

    Beside the already men­tioned plu­g­in, I also use the Objec­tion Redi­rec­tion plu­g­in ( I read about this in an arti­cle on a Perma­link Change by Dosh­Dosh. Does this still make sense if I apply the .htac­cess tool?

    Kind regards,

  16. I just did a hell­ish move from an extreme­ly out­dat­ed Mov­able Type instal­la­tion to Word­Press. All I want­ed was to redi­rect my old perma­link format:

    to my new format:

    I Googled for hours and tried all sorts of redi­rect rules, and noth­ing worked until your Redi­rect Match tip. THANK YOU!

    Lat­est from Michelle: Mouldy Speech­es

  17. Awe­some, exact­ly what I was look­ing for. Thank you so much for your fan­tas­ti­cal­ly clear infor­ma­tion, your help point­ing me to this arti­cle and your will­ing­ness to share addi­tion­al out­side links for fur­ther insight. I end­ed up hav­ing to go with the mod-rewrite ver­sion, but it works perfectly!

  18. Awe­some! Thanks a lot dude. You made my day, after search­ing up and down in the inter­net, try­ing few plu­g­ins which needs more tweak­ing works.. this one piece of code save the day!!!!!!!!!!!!!! :D

  19. Hi Rick — just want­ed to say a HUGE thank you for your clear and con­cise instruc­tions. They worked a treat when I changed my perma­link struc­ture and the search engines love it!

    Thanks again — you’re a genius :-)

  20. You rock, Rick! But you already knew that, right? :)

    I switched around my perma­link struc­ture last night–courtesy of — but the Redi­rect­Match line was­n’t work­ing correctly.

    After email­ing back and forth with Bruce, I had it down to 

    RedirectMatch 301 /([0-9]+)/([0-9]+)/(.*)$$3

    That solved the posts, but cre­at­ed a con­flict with date-based archive pages and uploaded images in date-based wp-con­tent fold­ers. One link led to another–and I came across this. I now have:

    RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/([a-z0-9-/]+)$1 and it works great!

    Bet­ter to use htac­cess than plu­g­ins I fig­ure; cleaner!

  21. When you say add it BEFORE the word­press code, do you mean before the line that starts “# BEGIN Word­Press” or just after that??


  22. Wish I had stum­bled on this site first, could have saved a lot of time. Thanks for the clear instruc­tions, worked a treat.

  23. I’ve just removed the date from my perma­links. Used to have the year and month in the URL but now changed it to just the post title. Haven’t seen an effect for SEO yet. I’m hop­ing that remov­ing the date will increase click through as peo­ple don’t want to click on a link where they know the con­tent is a cou­ple months old.

  24. Thanks for this great info. I’m just try­ing to fig­ure out a few details before pro­ceed­ing with this, and hope you can help. My cur­rent perma­link struc­ture is (set­up to mim­ic Blog­ger, since it was orig­i­nal­ly there):
    I want it to be:
    because some arti­cles (like this one ) sug­gest it’s bad for long-term scaleable per­for­mance to go direct­ly to postname.

    So based on your arti­cle, I assume I’ll just remove the “/[0 – 9]{2}” part, because I’m not using the day in the cur­rent perma­link? Then do I also need to do some­thing oth­er than the “$1” on the end, since it will now have the post ID before the name/slug? Thanks.

    1. I haven’t test­ed this, but try this out:

      RedirectMatch permanent ^/([0-9]{4})/[0-9]{2}/[0-9]{2}/([a-z0-9-/]+).html$1/$2/

      This assumes a /%year%/%postname%/ for­mat. The prob­lem with using the post num­ber is that your orig­i­nal perma­links don’t have that infor­ma­tion, so i’m unsure how to map it via regex to the new perma­links. Using the year alle­vi­ates the issue you men­tioned, though.

      Based on reports i’ve seen, the inef­fi­cien­cy with /%postname%/ perma­links is only an issue if you have many, many pages (posts are irrel­e­vant). By adding a num­ber (year, post num­ber, what­ev­er) to the perma­link, Word­Press more eas­i­ly dis­tin­guish­es between posts & pages and so the inef­fi­cien­cy is no longer there.

      Actu­al­ly, i seem to recall an update in Word­Press that fixed that issue alto­geth­er. Still, i chose to add the year to my perma­links here out of antic­i­pa­tion of some day hav­ing lots of pages (which may or may not actu­al­ly happen).

  25. Thanks for the response Rick. I was want­i­ng to use this plu­g­in: to pro­mote old posts (most of this site’s con­tent is not time-sen­si­tive). It won’t work if you use any dates in your permalinks.

    Now that you say that about it only being relat­ed to pages (not posts) and pos­si­bly fixed in a recent ver­sion of WP, I seem to remem­ber at least the lat­ter, as well. I’ll just go with the slug/post name, no post num­ber or any­thing. But I will add the “.html” on the end of the first part, to make it work correctly.

    So I don’t remove the “/[0–9]{2}” even though my cur­rent URL does­n’t have the day in it?

  26. No, you’re right about that: remove the unnec­es­sary point­er to the day!

    Also, Word­Press does a pret­ty good job of get­ting users to the cor­rect loca­tion after you change your perma­links. When i updat­ed perma­links here to include the year, i did­n’t have to do any­thing spe­cial to get old links to point to the cor­rect place. It just worked. I’m not sure if it’ll still work cor­rect­ly with the “.html” bit of yours, how­ev­er, so try it to see, and if it does work, you won’t need to mod­i­fy your .htac­cess file.

  27. Also, it seems like you’d be able to pro­mote old posts by set­ting their sta­tus to sticky tem­porar­i­ly rather than hav­ing their post time adjust­ed. That’ll make them reap­pear in feeds, which could annoy long­time sub­scribers. Prob­a­bly not, though. Just think­ing allowed. There’s just got­ta be a bet­ter way to accom­plish pro­mot­ing old posts than by mod­i­fy­ing post time, which would lead to the sit­u­a­tion of hav­ing post con­tent from 2011 that has com­ments on it dat­ing from 2009 or so… Not a huge deal, but i’m just obses­sive enough to be both­ered by it. :P

  28. Agreed. I’d pre­fer anoth­er method with­out rewrit­ing the date, but haven’t been able to find any­thing. Since most of my RSS sub­scribers are new, but a decent amount of con­tent is not (revived some­body else’s old blog­ger blog), I actu­al­ly want it to post and show up in the RSS as well. This is the best solu­tion I’ve found, so I’m going to give it a try.

    Thanks much for your help.

  29. I added this:
    RedirectMatch permanent ^/[0-9]{4}/[0-9]{2}/([a-z0-9\-/]+)\.html$1

    And it worked per­fect­ly! I decid­ed to go with­out the post num­ber. I installed that plu­g­in and we’ll see how it works.…

  30. Hel­lo i want­ed to change my per­ma link but not worked the redirect.

    my struc­ture is /%year%/%monthnum%/%postname%.html and want­ed to change to /%postname%/

    the redi­rect should still be Redi­rect­Match per­ma­nent ^/[0–9]{4}/[0–9]{2}/[0–9]{2}/([a‑z0‑9\-/]+)$1

    or i am doing it wrong?

    1. You would need to use a mod­i­fied redi­rect, which takes into account your unique struc­ture (####/##/example.html). I’m not sure entire­ly on how to account for the “.html” bit.

  31. old perma­links:


    and I changed it to: (new permalinks)


    How to Redi­rect old links after change of Perma­links? wiht HTACCESS?


    1. You could try adding this to your .htaccess file, though I haven’t test­ed it.

      RedirectMatch permanent ^/[a-z]+/([a-z0-9-/]+)$1

      Be sure to update the exam­ple domain name to your own.

    1. Not sure why — I’m by no means a reg­u­lar expres­sions guru. If you could share with me a few exam­ples of address­es which you want to work but which are redi­rect­ing to the home page, that could be useful.

      Til this, here’s a slight refine­ment which would account for cat­e­gories with mul­ti-word names:

      RedirectMatch permanent ^/[a-z-]+/([a-z0-9-/]+)$1
  32. I’m work­ing on it. As I said, not a regex expert, and so there’s a lot of tri­al and error on my part try­ing to find the right syn­tax. I’ll try to have an answer post­ed some­time today for you.

  33. The cat­e­go­ry one is going to be prob­lem­at­ic as its for­mat (/cat­e­go­ry/­cat­e­go­ry-name/) exact­ly match­es your old post perma­links (/cat­e­go­ry/­post-name/).

    Are you using the lat­est ver­sion of Word­Press? If so, chang­ing your perma­link struc­ture should be han­dled grace­ful­ly by Word­Press at this point, with­out the above cus­tom code. I may have imag­ined that, though, so you might look into the Perma­link Redi­rect plu­g­in to accom­plish what you want.

    Aside from that option, from the looks of it, in order to pre­vent your cat­e­gories from redi­rect­ing if this is nec­es­sary, you’re going to need a rather lengthy block of code which tests against every one of your cat­e­go­ry address­es, and if all of them fail, then it’ll redi­rect the post to the new post perma­link. This is going to be pret­ty inef­fi­cient as these tests will need to be made on every page load.

    1. I’m assum­ing the page that is redi­rect­ing is index.html? If that’s the case, then the redi­rect is work­ing prop­er­ly. Try these two lines together:

      RedirectMatch 301 ^/index.html$
      RedirectMatch 301 ^/([^/]+).html$$1
  34. Hi Rick,
    I am new to Word­Press and have recent­ly built a web­site, but the Perma­links were unfor­tu­nate­ly an after­thought. Now I am stuck with the old struc­ture which is /%123?%/ i.e. each page is just a num­ber. I want to change my perma­links so that they match the title of the page. I tried chang­ing this in the Word­Press options but when I then vis­it my site my brows­er just says page not found. Can you help buddy?

  35. Hi Rick,
    I am new to Word­Press and have built my site but unfor­tu­nate­ly I did­n’t give any thought to Perma­links… until now! Unfor­tu­nate­ly how­ev­er when I change the options in WP from the old struc­ture /%123?%/ i.e. just a page num­ber a new one which match­es the title of the page, when I then vis­it the site the brows­er just tells me “Page not found.” Can you help buddy?

  36. Hel­lo,

    My site was run­ning with perma­link struc­ture /%category%/%year%/%monthnum%/%day%/%postname%/ ear­li­er. Now I changed the struc­ture to /%category%/%postname%/ but the Old Url’s are not prop­er­ly redi­rect­ing back to new one. I tried the redi­rect rule Redi­rect­Match 301 ^/blog/([^/]+)/([0–9]{4})/([0–9]{2})/([0–9]{2})/([^/]+)/$$5.

    Can any one please help in writ­ing a prop­er redi­rect rule.


  37. I had this perma­link struc­ture /%category%/%year%/%monthnum%/%day%/%postname%/ and I changed it to /%postname%/. I added
    Redi­rect­Match per­ma­nent ^/([a‑z0‑9\-/]+)/[0–9]{4}/[0–9]{2}/([a‑z0‑9\-/]+)$2 line to htac­cess, all works fine and all the ear­li­er posts with old­er perma­link are redi­rect­ed to new perma­link struc­ture but many of the images in the home page are bro­ken. could you sug­gest how to fix this?

  38. Hi Rick, this is a real­ly cool arti­cle! One ques­tion: I’m using seo yoast, I pub­lished a page and I want to change the perma­link (just to add a more friend­ly key­word). How can I do it with­out to get a 404 error? Thank you so much!

Leave a Comment

Your email address will not be published. Required fields are marked *

Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

Comments must be made in accordance with the comment policy. This site uses Akismet to reduce spam; learn how your comment data is processed.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Rick Beckman