How to Remove the Date from a WordPress Post URL

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: when you update that post, what should you do? Leave it’s URL looking old? Move it to the new one and worry it’ll 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.

In this Quick Guide about WordPress, learning to change a permalink structure will be our goal. The problem: while toggling the setting itself can work, will cause your WordPress site to present 404 errors at your old URLs. The trick we’ll cover in this video (and written tutorial about WordPress): URL rewrites with .htaccess files.

As always, we’ll start with this video. In this one I explain 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:

  1. 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.
  2. 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.”
  3. 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.
  4. 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.
  5. 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>
  6. 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. 🙂


9 Responses

Comments

  • MahMoud AsFour says:

    when i change the permalink settings only the date disappear from a post link without edit “htaccess” file
    why this ?

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

  • Felicia says:

    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?

    • Fred Meyer Fred Meyer says:

      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? 🙂

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

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

  • haseeb says:

    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)

  • Neha says:

    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.

Add a Comment

Your email address will not be published. Required fields are marked *