Removing Year, Month, Day from WordPress Permalink Structure

Nick Wilson from Performancing recently interviewed Matt Cutts from Google regarding SEO for bloggers. When Matt speaks I listen. One particular Q/A caught my attention.

Q. Can you give the Performancing readers a few tips on ranking in Google?
A. I wouldn’t bother with year/month/day in blog urls; I’d just use the first few words from the title of the post in the url.

That is a nice nugget of SEO advice. The next question becomes, how do I make that change in WordPress? Before answering that question, you first want to investigate if that is something you really want to do. For one, the WordPress documentation stresses against it:

Note on using only %postname%
If you use postname as the only element in your permalinks to create a structure such as myblog.com/post-title, the rewrite rules may make it impossible to access pages such as your stylesheet (which has a similar format) or the wp-admin folder. It’s best to include some numeric data (e.g. the post ID or date) in the permalink to prevent this from happening. Additionally, WordPress v1.2.x requires the use of a date structure in order for some features, such as the calendar, to function properly. /%year%/%monthnum%/%day%/%postname%/ is always a good start.

Additionally, there has been debate that getting your blog into Google News requires URLs that have at least four numeric values. I have no idea if that is true or not, investigate the links you find at Google News yourself. I’ve seen people stress it is a requirement and others who say it is not.

Even if you decide not to heed the strong advice in the WordPress documentation there are other considerations. How well is your site indexed by the search engines and how quickly will they find all of the new pages and discard all of the old pages? While the search engines deal with the URL change on your site will you give yourself a duplicate content penalty in the process? Those are some items you will need to consider.

Also, we know things like PageRank are depend on incoming links to individual pages, now they will be linking to the old page. So if you decide all of the other factors are an okay risk you will want to perform a 301 redirect from the old URLs to the new URLs. Therefore (hopefully) PageRank will be retained by the 301 and visitors who get to your site from an old link will not arrive at a 404 “file not found” page. And you might be less likely to receive duplicate content penalties with the 301 redirect in place.

Note these directions were designed for WP 1.5x users and will not be the same in WP 2.0. Further I had difficulty the first time I tried this in WP 2.0

If you still want to do this, I would suggest following these steps. Go into the admin section of WordPress, click on ‘Options’, and then Permalink Structure. In the Structure field use “/%postname%/” without the quotes and then click ‘Update Permalink Structure’. Now open the .htaccess file at the root of your WP installation and add the following line at the very, top of that file.

RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$ /$4/ [R=301,L]

Now test to make sure that links on your blog work properly and use the new URL. Also make sure if a visitor clicks on an old style link they are redirected to the new style URL.

Explore posts in the same categories: Computer Technology, SEO Search Engine Optimization

13 Comments on “Removing Year, Month, Day from WordPress Permalink Structure”

  1. Chip Cuccio Says:

    Nice hint on the mod_rewrite rule. I may have to give it (removing the date from my URIs) a shot.

  2. Chip Cuccio Says:

    The only way I could get the redirect to work, was to place the following *before* WP-generated rules:


    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$ /$4/ [R=301,L]

  3. Chip Cuccio Says:

    Gah…

    The ” RewriteRule” and is supposed to be on one big line. Sorry folks :-)

  4. Chip Cuccio Says:

    Same problem I had until I added my rule;

    http://www.timflight.com/2005/12/30/why-im-not-upgrading-to-wordpress-20-yet/

  5. Tim Flight Says:

    Interesting, mine is certainly working okay at the bottom.

  6. Chip Cuccio Says:

    I’m getting a 404 on one of your posts (old URI structure);
    http://www.timflight.com/2005/12/30/why-im-not-upgrading-to-wordpress-20-yet/

    I was getting similar 404’s until my implementation.

    Sorry for all the comment spam :-)

  7. Tim Flight Says:

    Oh yea, interesting. I swear it didn’t work the first time I put it at the top. Thanks for the fix!

  8. Sebastian Says:

    Hello guys,

    I a running WP 2.0, have changed permalinks to %postname%, and have tried both solutions suggested and neither works. Have tried both of them at the beginning and at the end of the WP-generated rules, and still I get that dreaded File Not Found 404 error.

    Any ideas? Who can think of a rule that works under WP 2.0?

    Any help greatly appreciated!

    Regards,

    Sebastian (from Argentina)

  9. Tim Flight Says:

    Hi Sebastian,

    I upgraded to WP 2 and this continued to work fine. I would suggest backing up your .htaccess file, creating a new blank .htaccess file, and letting WP rebuild the contents of that file via the admin panel.

    If that doesn’t work maybe let us know the URL of the site and what your .htaccess file looks like.

  10. Sebastian Says:

    Hi Tim, thanks for the response. The site is http://www.tecnonauta.com (I guess the name would be appropriate for you, since it has the two things you enjoy, ‘tech’ and the ‘naut’ as in astronaut). Anyway, the htaccess is like this:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$ /$4/ [R=301,L]

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php

    An example of a link that doesn’t work is this:
    http://www.tecnonauta.com/20060117/microsoft-da-software-gratis-para-migrar-de-lotus-notes-y-domino.html

    (sorry, the perma is terribly long). I’m thinking now that perhaps the rewrite rule does not work because I compacted year, month and day all in one subdirectory /20060117/ (2006, january, 17)?

    Once again thanks, any help appreciated… it break my heart to see the “Error 404 no found” message.

    BTW, have you experienced any problems with the %postname% only perma? Any instance of the issue the codex talks about, not being able to read the CSS?

    Thanks and greetings… also, you have a very polished, nice design in your ‘family’ of sites… The Blog studio does nice work. Don’t you go crazy writing 100 posts in a week? It’s admirable

    Cheers,

    Sebastian

  11. Sebastian Says:

    Sorry, I have another random observation… it’s interesting that Aquarius (which seems to be your sign) is precisely the sign associated with both computers and flying (and all things ‘gadgety’). Keep the Uranian spirit up :)

  12. Tim Flight Says:

    Hi Sebastain,

    The link you provided doesn’t work because it doesn’t fit the format of what the rewrite rule is trying to accomplish. (As you thought might be the case.) The rewrite rule provided will take a URL like this:

    http://www.tecnonauta.com/2006/01/17/microsoft-da-software-gratis-para-migrar-de-lotus-notes-y-domino.html

    And redirect it to this:

    http://www.tecnonauta.com/microsoft-da-software-gratis-para-migrar-de-lotus-notes-y-domino.html

    Notice the difference with the slashes. What did your URLs look like before you changed the permalink structure?

    I have not experienced the problems hinted at in the codex. I suspect that might have been a problem with WordPress versions before 1.5. I have not seen it happen in 1.5 or 2.0.

    At first I did go crazy writing 100 posts per week. In fact at first just writing one post per day seemed like a huge chore. But now that I’ve been working at it for some time I’ve become more efficient at writing quality posts. I still wish I was more efficient, however I’m getting better all of the time.

    I knew Aquarius was associated with flying (Pegasus, the winged horse), however I didn’t know it was associated with gadgets. Good to know, thanks!

  13. Vitor Hugo Says:

    Hi Tim, I want thank you so much! Your tip helped me a lot! :) Cheers! o/