Latest TweetsVerify any search engine or visitor via CLI Forward-Reverse Lookup perishablepress.com/cli-forwar…
Perishable Press

Permalink Evolution: Customize and Optimize Your Dated WordPress Permalinks

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 permalinks1. 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.

Permalink Evolution

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, 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 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:

# remove all permalink date info for blog in root directory
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$ http://domain.tld/$4/ [R=301,L]

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!

Option 2: Remove “year/month/day” from permalinks with WordPress installed in SUBDIRECTORY

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

http://domain.tld/subdirectory/2008/08/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 all permalink date info for blog in subdirectory
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?$ http://domain.tld/subdirectory/$4/ [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 3: Remove “year/month” from permalinks with WordPress installed in ROOT directory

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

http://domain.tld/2008/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:

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

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!

Option 4: Remove “year/month” from permalinks with WordPress installed in SUBDIRECTORY

This method removes the “year/month/day” portion of permalinks for blogs located within a subdirectory. So 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 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:

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

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!

Option 6: Remove “year” from permalinks with WordPress installed in SUBDIRECTORY

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

http://domain.tld/subdirectory/2008/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 info from permalinks for blog in subdirectory
RewriteRule ^([0-9]{4})/([^/]+)/?$ http://domain.tld/subdirectory/$2/ [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!

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!

Footnotes

  • 1 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. In addition to the information provided in Rick’s article, this post expands context, explores consequences, and presents an alternate technique including multiple configurations for custom permalinks.

Jeff Starr
About the Author Jeff Starr = Creative thinker. Passionate about free and open Web.
Archives
58 responses
  1. Jeff Starr

    Thanks, I appreciate the positive feedback. I am glad that the article continues to be helpful. Also, interesting information about the digg badges. Never heard of it before, although it does seem logical now that you mention it. I can see how this issue would be a serious consideration for highly dugg sites that are contemplating modifying their permalink format. Fortunately for me, I enjoy my relatively low profile and won’t need to worry about it once I take the plunge and make the switch. Great comment — thank you :)

  2. Gaius Parx August 17, 2008 @ 8:49 am

    I remembered reading somewhere that it is good SEO practice to include numbers in your URL, search engine tends to like URL ith numbers on it. Anyone can clarify?

  3. Jeff Starr

    Actually, just the opposite is frequently argued to be the case. Referring to dateless permalinks as “timeless” or “evergreen,” many say that omitting date information from your links gives the impression that the content is always relevant. There are also arguments that shorter links are better for SEO because the search engines often advise keeping directory structures as “flat” as possible.

    Personally, I prefer including the date in links for technical/tutorial sites such as Perishable Press because it provides chronologically contextual information that may benefit visitors when searching for accurate and relevant solutions. For more discussion on this issue, check out my post on rethinking permalink structure.

  4. My problem is a little bit odd —

    I changed my permalink structures to /%post_id%/%postname%/ which caused my archives to go nuts.

    Now the archives are /date/%monthnum%/%year%/ and old incoming archive links are like /%year%/%monthnum%/ but I can’t get modRewrite to parse it correctly.

    What might I do differently here?

  5. Great articles. Thank you so much for going to the effort. It’s a great help.

    But now I have problem I can’t seem to figure out. I need to redirect a call to the root when there’s nothing passed on the URL.

    Redirect: www.domain.com/

    Don’t re-direct: domain.com/index.php or domain.com/?p=385

    I got a redirect working, but it also redirects with the ugly links starting with a ? . so the second example above will redirect but should not.

    This is the line I’m using to redirect:

    RewriteRule ^$ http://liveearth.org/SplashPage/index.html [R=301]

    Thank you very very much in advance for any help you can give.

  6. Jeff Starr

    Hi Gabriel, if I understand you correctly, you would like to redirect all requests for the site’s root URL to another page, but all subsequent pages should not redirect..? If this is the case, I have good news. I get this question so frequently that I have written a complete article that explains everything and provides the perfect solution. I will be posting the article tomorrow, so stay tuned to catch it!

  7. I’ve used Option #4 twice and the .htaccess “loses” or “erases” the change and it reverts back to the same as it was before we added the code.

    Any ideas as to how to get this to “stick” ?

    Thanks !

  8. Jeff Starr

    @Mike: I recently experienced this exact same issue. Turns out that the culprit was the automated cPanel hotlink protection rules. Long story short, cPanel “erases” your htaccess file while writing its own anti-hotlinking directives. For the long story, check out this article. That may not be the issue, however based on the symptoms you describe, it’s my best guess and definitely worth checking out..

  9. Thanks Jeff, I’ll check it out !

  10. How do you deal with remapping trackback and feed links?

    ex http://domain.tld/2008/12/12/post-name/feed/

    This doesn’t get remapped as it fails the regexp. I wish I had the fix to post here but I’m struggling to find the correct regexp to deal with feeds and trackbacks.

    Jeff

  11. Jeff Starr

    @Jeff: Are you referring to trackbacks generated by WordPress that appear on your own site? If so, I would think that the same logic would apply: existing links will be redirected, while new trackback links will obey the updated permalink structure as specified via the WordPress admin? Although I could be missing something here..

  12. @Jeff Starr: Yeah, the trackbacks were a bad example. I happened to be looking through my logs after using the htaccess redirect you showed and noticed that all of the old date based URLs ending with /trackback or /feed were not getting redirected.

    The /feed ones are more important.

    http://domain.tld/2008/12/12/post-name/feed/ doesn’t seem to get redirected to http://domain.tld/post-name/feed/ for me. The last part of the RewriteRule shown (([^/]+)/?$) appears to only match the “/post-name/” if that is the end of the URL. By having the dollar sign at the end and matching everything except a “/”, I don’t think it will match trailing stuff like “/feed” after the post-name. I’m also not sure about URLs with trailing anchors (like #comment-55).

    The “/feed” would be for users who have subscribed to the post comment feed

    Ironically, I only have bots and spammers that try to hit those URLs, but I’d rather not return a 404 if they should be able to resolve the URL.

    I have a very hacky solution that appears to work for my site if you’re interested. I won’t post it though as I’m not sure what else it might break. :)

[ Comments are closed for this post ]