So, you want to remove the date from your WordPress post URLs? I get it. Those /2016/07/09/post-slug
URLs that seemed pretty cool when you (or someone else) set it up get old.
The primary reason those date URLs are an issue: when you update that post, what should you do? Leave it’s URL looking old? Move it to the new one and worry the link will break? These concerns are why we use the “Post name” option for WordPress permalinks here at WPShout and encourage most of our clients to do the same.
Step One in Rewriting WordPress Permalinks: Do No Harm (To Your Site’s SEO)
In this Quick Guide we cover how to change a WordPress permalink structure. The problem: while toggling the setting itself can work, will cause your WordPress site to present 404 errors at your old URLs.
What’s wrong with that? It will tank the SEO of the site you’re working on. If you’re curious what that means, we strongly suggest you read our article on WordPress SEO mistakes before moving further.
How to Rewrite WordPress URLs
The trick we’ll cover here to avoid generating 404s on our site: we’ll do our URL rewrites with .htaccess
files.
Here’s a video explaining how I change permalink structure for a WordPress post, and make sure that I forward all the traffic to the old URLs to the new ones:
WordPress URL rewrite with .htaccess
: the Code
When I simply remove post dates from URLs, WordPress is confused. It knows my “new” permalink settings, but it immediately forgets the old one. So we have to help it, that’s where this URL rewrite in .htaccess
rule comes in: it’ll make sure that WordPress never sees our old permalink structure. Here’s the code, which you’ll typically put in a file called .htaccess
which will be at the root of your WordPress site’s file system:
## 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>
The really important thing about this code: it requires that your WordPress server be running “Apache” not “Nginx,” and that your Apache configuration support .htaccess
files for URL rewrites. I mention this because this is the only way to remove the date from a WordPress post URL we’ll cover in this Quick Guide. But if you’re struggling, hopefully that gives you some helpful pointers on where to look next.
Step-by-Step Guide to Remove the Date from a WordPress Post URL
So if you want to change your permalinks to remove post date in WordPress, here’re the steps we recommend you take:
- First, you’ll want to change the permalink settings. To do that, navigate to “Settings > Permalinks” in the left bar of the WordPress admin area.
- The rest of this tutorial assumes that you’ve chosen URLs like
mysite.com/post-slug
. If you do want that URL structure for WordPress, select “Post name” (the fifth option as I write this) on the Permalink Settings page. Press “Save Changes.” - Now, to supper WordPress, we’ll do a URL rewrite with htaccess. As mentioned above (don’t worry if you didn’t use it) to change the change permalink structure for WordPress posts, we’ll need to find the .htaccess file. This is most easily done by first connecting to your web host via SFTP. If you’re new to that, here’s a guide.
- Once connected, find the
.htaccess
file at the root of your WordPress installation. Here’s where we’ll put the code to change our permalink structure for WordPress to remove the date. - URL rewriting is doing by
.htaccess
for *most* WordPress sites. So we’ll open up that file, and paste in these lines:## 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>
- Save and upload that file back to the server. With that, you should have successfully removed the date from your WordPress post URLs, without triggering a bunch of 404 errors.
Changing permalink structures in WordPress can be daunting, but hopefully we’ve guided you through. 🙂 If this is a new topic to you, we again strongly recommend you read up on SEO mistakes before attempting something like this the first time, as they’re one of the few types of mistakes in WordPress that can be impossible to quickly fix.
“My Developer Ruined My Site’s SEO”: Three Huge SEO Mistakes and How to Avoid Them
This didn’t work for me. It just did nothing at all. Why, I wonder… ?
THX! This also works with LiteSpeed servers. At least it worked for us 🙂
I am using the free version from wordpress.com and I cannot find the permalink option. Does this only work for those with their own domains or upgraded plans?
I am trying to do that for my blog but getting 404 error on some posts. Don’t know how to restore that.
Can I anyone let me know about 504 error. I face this error several times I talk to server team but they don’t fix
Hi, I’m into similar issue but I cannot locate htaccess in my wordpress site. Please suggest as I tried to locate it in SEO -> tools -> file editor. htaccess does not exist at this location.
its only for apache , can anyone help me as how to use this with Nginix (my blog is launched on AWS cloud so i am using cloudfront and nginix)
Hi,
Guide to Remove the Date from a WordPress Post URL
I don’t know this before when search it on google i have found your website at here and read your written article and try to change my self then i have done after apply it on my website.
Thanks a lot for your beautiful article.
Hi,
Step-by-Step Guide to Remove the Date from a WordPress Post URL
I don’t know this before when search it on google i have found your website at here and read your written article and try to change my self then i have done after apply it on my website.
Thanks a lot for your beautiful article.
1. Do you think you’ll ever write advice for those of us who have an nginx-based managed Word Press server like Liquid Web (whom you recommend)?
2. I have over 3000 posts on my site going back to 2012. All were crested using the date/slug format. I have a plug in by Yeost that will create a redirect for individual posts on which I change the URL, but it doesn’t support bulk changes. And WP tells me(as I understand it) that changing my URL settings is retroactive, therefore would cause 404 errors on every past post. Is there a solution you know of that could handle creating redirects for all of my posts in one fell swoop? As above, it would have to be usable on an nginx server. Maybe this could be a subject for a future post?
Hi Felicia,
Great questions! We don’t know a ton about writing nginx rules ourselves, so our solution on nginx-based hosting environments (e.g. WP Engine uses nginx reverse proxy) has been to get a tech support person on the line, explain exactly what we’re looking for, and not hang up the phone until the resulting redirects work properly . Have you tried that? 🙂
Thank you for this tutorial.
I tried changing my permalinks before, the result was not good. I had so many 404 errors but I couldn’t figure out what was wrong. However, I have just done it again following your guidance, and it as worked well.
Thanks for the .htaccess code.
Great! Glad it helped you 🙂
when i change the permalink settings only the date disappear from a post link without edit “htaccess” file
why this ?