How to streamline and maximize the effectiveness of your WordPress URLs by using htaccess to remove extraneous post-date information: years, months, and days..

Recently, there has been much discussion about whether or not to remove the post-date information from WordPress permalinks 1. Way back during the WordPress 1.2/1.5 days, URL post-date inclusion had become very popular, in part due to reports of potential conflicts with post-name-only permalinks. Throw in the inevitable “monkey-see, monkey-do” mentality typical of many bloggers, and suddenly an entire wave of WordPressers had adopted the following permalink structure:

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

The benefits of using this format are primarily organizational in nature. Post-date information that is “built-in” to every URL provides immediate, “at-a-glance” knowledge of post “freshness”. Looking ahead ten, twenty or even a hundred years into the future of the blogosphere, there will be trillions of posts and articles, each with their own unique URL. Archived copies of content may or may not include creation date: dynamically archived pages require deliberate database queries, while those archived statically may no longer have access to post-date data. Including post dates in permalinks provides permanent, facilitative record of content origination. Needless to say, most adopters of dated permalinks probably jump on board because the WordPress Admin makes it super-easy to follow the crowd.

Over time, however, as understanding of search engine optimization permeated the blogosphere, many people who had embraced such “dated URLs” began rethinking their approach to permalinks. Eventually, the trend had reversed, as SEO-savvy bloggers avoided dated permalinks like spider pig. These days, a majority of bloggers initialize their permalinks with either a “category/name” or even a name-only URL format:

/%category%/%postname%/
(or)
/%postname%/

Of course, the benefits to this simplified structure are largely utilitarian in nature. Removal of post-date information effectively reduces the length of permalinks. Shorter permalinks provide greater usability for both humans and machines: people may find such URLs easier to read, while search engines may interpret the permalink as containing a more concentrated array of keywords. Further, search engines such as Google often display a limited number of characters in their search results. Elimination of expendable characters from your URLs results in more (if not all) of your actual post title being displayed to people as they scan the search results. Finally, shorter permalinks are simply easier to work with. They are easier to share, require (slightly) less bandwidth, and look considerably cleaner.

So, as we make our way into 2008, it appears that it is time to evolve our permalinks toward cleaner, shorter, more concise formats, with redundant information such as “year/month/day” either entirely omitted or dutifully removed. If you are setting up a new WordPress-powered site, and have not yet decided on a permalink structure, I would highly advise against inclusion of date information. Likewise, if you are running an established site that has been using dated permalinks for any length of time, you may want to join fellow bloggers such as Rick Beckman and remove the dates from your URLs.

How to remove the “year/month/date” portion of dated permalinks

Although there are free WordPress plugins available for changing your permalinks(404 link removed 2012/12/01), we prefer to handle URL redirection with Apache/htaccess rather than PHP because it requires fewer system resources and is executed with greater speed. One final note before we begin: the purpose of this tutorial involves removing date information from all future permalinks and redirecting all preexisting permalinks to their restructured counterparts. Thus, if you are setting up permalinks for a new blog (or one with only a few posts), the second part of this tutorial may not be required — a simple change of permalink structure via the WP Admin (as explained below) may be all that is needed. That said, let’s begin..

Part 1: Update your WordPress Options

The first step in creating “post-name-only” permalinks is to update your WordPress permalink structure in the Permalinks Options page of the WordPress Admin. Using the Custom structure option, customize your permalink structure as follows:

/%postname%/

After entering the post-name-only permalink structure, save the changes and test your pages. Remember to check different types of views — home, single, archive, page, search, etc. — to ensure that your new permalinks are working as expected. Once this is done, all future posts will feature the dateless permalink structure. In the second part of our tutorial, we will redirect all requests for old versions of your URLs to their newly configured counterparts.

Part 2: Update your htaccess file

The second step in creating “post-name-only” permalinks involves modifying your root or subdirectory htaccess file to ensure that old permalinks are redirected to, and served as, your new permalinks. Examine each of the scenarios described below, determine which method applies to your specific setup, and implement the required steps.

Option 1: Remove “year/month/day” from permalinks with WordPress installed in the ROOT directory

This method removes the “year/month/day” portion of permalinks for blogs located within the domain’s root directory. So, for example, if your old permalinks looked like this:

http://domain.tld/2008/08/08/post-title/

..then the htaccess code provided in this section will transform them into this:

http://domain.tld/post-title/

Locate your blog’s permalink htaccess rules. Then, place the following code directly after the line containing the RewriteBase directive:

Remember to edit the “domain.tld” to match that of your own. No other changes are necessary. Test like crazy. After verifying that everything works as intended, sit back and enjoy your new optimized permalinks!

Remember to edit the “domain.tld/subdirectory” to match that of your own. No other changes are necessary. Test like crazy. After verifying that everything works as intended, sit back and enjoy your new optimized permalinks!

Remember to edit the “domain.tld” to match that of your own. No other changes are necessary. Test like crazy. After verifying that everything works as intended, sit back and enjoy your new optimized permalinks!

This method removes the “year/month/day” portion of permalinks for blogs located within a subdirectory. So, for example, if your old permalinks looked like this:

http://domain.tld/subdirectory/2008/08/post-title/

..then the htaccess code provided in this section will transform them into this:

http://domain.tld/subdirectory/post-title/

Locate your blog’s permalink htaccess rules. Then, place the following code directly after the line containing the RewriteBase directive:

# remove year and month info from permalinks for blog in subdirectory
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)/?$ http://domain.tld/subdirectory/$3/ [R=301,L]

Remember to edit the “domain.tld/subdirectory” to match that of your own. No other changes are necessary. Test like crazy. After verifying that everything works as intended, sit back and enjoy your new optimized permalinks!

Option 5: Remove the “year” from permalinks with WordPress installed in ROOT directory

This method removes the “year” portion of permalinks for blogs located within the domain’s root directory. So, for example, if your old permalinks looked like this:

http://domain.tld/2008/post-title/

..then the htaccess code provided in this section will transform them into this:

http://domain.tld/post-title/

Locate your blog’s permalink htaccess rules. Then, place the following code directly after the line containing the RewriteBase directive:

Remember to edit the “domain.tld” to match that of your own. No other changes are necessary. Test like crazy. After verifying that everything works as intended, sit back and enjoy your new optimized permalinks!

Remember to edit the “domain.tld/subdirectory” to match that of your own. No other changes are necessary. Test like crazy. After verifying that everything works as intended, sit back and enjoy your new optimized permalinks!

Wrap it up..

Using your choice of the methods described above, it is possible to optimize and maximize your WordPress permalinks for greater usability, better performance, and enhanced SEO value. Many thanks to Rick Beckman for his idea, insight, and inspiration regarding the process of removing dates from permalinks. And, as always, please share any questions, comments, or criticisms in the comments area below.

God Bless!

1Editor’s Note: This post was written shortly after Rick Beckman inquired about removing the post-date information from his permalink URLs. After discovering a solution, I wrote this article to explain the method, and intended to post it upon returning to the office. After finishing the article, I was surprised to learn that Rick had already discovered a similar solution, implemented it at his site, and published an excellent article explaining his process. Having said that, I tip my hat to Rick for beating me to the punch, and have decided hesitantly to share my write-up on the technique as well. In addition to the information provided in Rick’s article, this post expands context, explores consequences, and presents an alternate removal technique including multiple configurations for custom permalinks.

@Xero: yes, that’s been known about for awhile now, and I agree that it should be addressed in future versions to improve scalability. But I’ve also read that for 99% of sites out there everything is going to be just fine with dateless (non-numeric) permalinks. It’s only when you start talking about thousands and thousands of posts and/or extremely large amounts of traffic that any performance impact from permalink structure is noticed. From what I’ve read about it, anyway.

For over 2 months now, I’ve been redirecting my old permalinks using Permalink Redirect by Scott Yang without a hitch until this morning when I accidentally discovered that the redirects where no longer working.

I was wondering if there was a way of setting these redirects via htaccess.

My old permalinks are

/%category%/%postname%/%postname%.html/%post_id%/%postname%.html

and until now, they were all been redirected to /%postname%/%post_id%/

My wordpress installation is in the blog folder not the domain root.

I’d appreciate any help you could render despite your time constraints. My web host is yet to reply the support ticket I just submitted.

Thanks for the “pretty permalink” change info. I was hesitant to make the change as I had read at WP.org to not change to a permalink beginning with category or post name, so I was a bit concerned about doing so.

My question…I am changing over from a default that includes the post id. Would you recommend a htpaccess modification, or would a 301 redirect work fine? A previous post here mentioned problems with a 301.

If an htpaccess modification is preferred, is it basically the same route explained above for the change from month & date, to post name?

Ok, so I had a setup where I had my blog posts in a subdirectory (wordpress installed in the root) and followed your remove year/month from subdirectory bit… however all the old requests showed up as 404s…

A bit of digging and I have added the subdirectory to the rewrite rule…

Books

Links

About the site

Perishable Press is the work of Jeff Starr, professional developer, designer, author, and publisher with over 10 years of experience. Check out some of Jeff's books and projects, follow on Twitter, or learn more »

Fun fact: Perishable Press has been online since 2005, and now features over 700 articles and more than 11,000 comments. More stats »