Changing your Permalink Structure
For many bloggers just starting out, when we first setup our blogs, we may select to include the year and month (and sometimes even day) in the title of your blog posts. So, for example, on my site “My Dreams of Disney”, I have a blog post that is this permalink: https://mydreamsofdisney.com/2017/12/looking-for-a-disney-getaway/
The format for that link tells me that the permalink is set for “Month and name” format. You can see that after the domain name, the year 2017, followed by the 2 digit month 12, tells me that the post “Looking for a Disney Getaway” was written in December, 2017.
Some bloggers even go with the “Day and name” format; if that were the case on My Dreams of Disney, then the link would be something like this: https://mydreamsofdisney.com/2017/12/18/looking-for-a-disney-getaway/, which tells me that in this example, the post Looking for a Disney Getaway was written on December 18, 2017.
For most people, setting month and name is perfectly okay, and for many bloggers, they may never need to change that format. Some bloggers, though, as their site gains traction, may find that some of their early writing is needing to be updated with new content. Over time, that can cause headaches. For example, what do you do if you update a post from 2012 with new content? Do you republish it with a new post so that it has 2019 in the year? If you do that, what affect does that have on your Google SEO rankings? If the posts are nearly identical, it may very well cause you to be penalized in your SEO scores because of the nearly duplicate content. So what are you to do?
If you find yourself in this predicament, there are some easy solutions to your problem. I know this because I have recently explored the problem and solved it for one of my major clients and her website. The rest of this post will go into detail how you can make the change so that your site can be updated as well and still function.
Changing the WordPress Permalinks structure
If you are in your WordPress dashboard, go to settings, and select Permalinks from the menu. This will allow you to see and configure your Permalinks structure.
As you can see in that screenshot, the common settings are Plain, Day and name, Month and name, Numeric, Post name, and a Custom Structure. For My Dreams of Disney, I have selected Post name, although last week I was running it as Day and name.
Changing the structure is as simple as selecting the setting you prefer and then clicking save at the bottom of the page. As soon as you do that, your site permalinks will change. What was once https://mydreamsofdisney.com/2017/12/looking-for-a-disney-getaway/ will automatically become https://mydreamsofdisney.com/looking-for-a-disney-getaway/. It’s as simple as that.
However, there is another step that needs to be taken because if you don’t implement the second step, people that click on any links that exist out in the internet, either on Facebook, or Pinterest, or Twitter, or any other social media locations, will receive a 404 error telling them that the post can’t be found.
I struggled with this for far too long, worried that I was going to mess it up for my client. I looked at all sorts of plugins that would take care of it for me. I pondered whether to use the Redirection plugin, or the 301 Redirects plugin, or any number of a hundred plugins that handle redirects on WordPress sites.
However, I learned a really neat way to handle redirects using the .htaccess file in your website. The key component, though, is that your website needs to be running Apache and not Nginx. Also, there are multiple .htaccess files in your file structure, the one you want to modify is the file that lives in the root of your WordPress installation. For me and most users, that location is in your “public_html” folder on your host. Special shoutout to David Hayes with wpshout.com for writing the post that I learned from! Here’s his direct link if you wish to just go there: https://wpshout.com/quick-guides/remove-date-from-wordpress-post-url/
The code listed below is when you have the “Day and name” convention for your permalinks. I’ll also post code that will work when you have the “Month and name” convention.
## To change example.com/2019/01/01/post-slug to example.com/post-slug <IfModule mod_rewrite.c> RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4 [R=301,NC,L] </IfModule>
This code is for the “Month and name” convention for your permalinks.
## To change example.com/2019/01/post-slug to example.com/post-slug <IfModule mod_rewrite.c> RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ /$3 [R=301,NC,L] </IfModule>
To summarize what that code means, in the “RewriteRule” linke, the first set of ([0-9]+) is the year, the second set of ([0-9]+) is the month, and if you have the day also, then the third set of ([0-9]+) is the day. So, what that rule is telling Apache to do is to look at either the 4th set or the 3rd set (depending on which rule you are using) and just keep that with a 301 Redirect (that’s what the R=301 is about, a 301 (permanent) redirect. The NC is shortcode for no case, meaning that Apache doesn’t care if any of the URL has upper or lower case. Lastly, the L simply tells the mod_rewrite.c program to stop processing if the rule matches. Since this is the only RewriteRule in this string, though, that’s mostly irrelevant.
To summarize, your changing your WordPress permalinks structure is super easy, but there are two steps you need to take care of for established sites.
- Change the permalinks structure in your WordPress settings on your Dashboard.
- Write a RewriteRule into your .htaccess file that will tell links to strip out the year and month (and day, if necessary) so that WordPress knows what to do with an old link.
Thank you so much for stopping by, and special thanks to WPShout.com for teaching me about this! If you need any help that you aren’t finding, reach out and I’ll be happy to attempt to help. Thanks, have a great week!