Save 25% on Wizard’s SQL for WP w/ code: WIZARDSQL
Web Dev + WordPress + Security

Redirect WordPress Date Archives with .htaccess

Restructuring a WordPress website may involve removing the subdomain from URLs/permalinks. For example, I recently removed the original WP-install subdirectory from Perishable Press to simplify site structure and optimize WordPress permalinks. There are PHP scripts and WP plugins that might work for this, but in most cases .htaccess is optimal when changing URL structure and redirecting traffic. Here’s a quick example to help visualize the concept:

Old structure (w/ subdomain)

New structure (w/out subdomain)

We also want to redirect date-archive permalinks when they’re paged or missing the trailing slash. Note that here we’re dealing with WordPress date archives, which is different than simply removing the “year/month/day” from your single-post permalinks. We’ll get to doing that a bit later, for now let’s remove the subdirectory from the date-based archives.

Redirecting date archives

First, if you’re familiar with using .htaccess, you may be asking, “why is this even necessary? Why not just redirect *everything* from the subdirectory?” Good question. If you have WP installed in a subdirectory structure like this:

..and want to redirect to basically the same thing, only without the wordpress subdirectory:

such that there is basically a one-to-one correspondence between old and new files, then YES you can just redirect everything wholesale with a simple line of .htaccess:

RedirectMatch 301 ^/wordpress/(.*)$1

and be done with it — no need to bother with the other redirect methods in this tutorial. If, however, your site restructuring is more complicated, perhaps involving stuff like:

  • you also want to remove the year/month/day from your single-post permalinks
  • you are removing/renaming/consolidating directories, so not 1-to-1
  • you are changing tag/category/taxonomy names, so not 1-to-1
  • other subdirectory installations of WordPress are involved
  • you’re just nuts for even thinking about this crazy stuff

If any of these apply, then the easy way is out and you’ve got some thinking to do. I’m here to help with that, starting with redirecting your date-based archives. Here is the magic code to add to your site’s root .htaccess file (after making a backup copy of the original):

RedirectMatch 301 ^/wordpress/([0-9]+)/?$$1/
RedirectMatch 301 ^/wordpress/([0-9]+)/page/(.*)$$1/page/$2

RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)/?$$1/$2/
RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)/page/(.*)$$1/$2/page/$3

RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)/([0-9]+)/?$$1/$2/$3/
RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)/([0-9]+)/page/(.*)$$1/$2/$3/page/$4

There are three sections to this code: yearly archives, monthly archives, and daily archives. The only editing that you need to do is change the “wordpress” in each line to match your subdirectory’s name, and then also replace all instances of with your domain name.

Eliminate all date-based archives

You may have asked at some point, “why bother at all with date-based archives?” After all, it’s redundant info that may contribute to “duplicate-content” penalties in search-engine results. I think most blogs these days emphasize categories and tags over the myriad other archive types. Many themes tend to ignore the date-based archives and popular SEO plugins provide easy ways of no-indexing/removing them from search engines. So let’s just eliminate date archives entirely, say by redirecting all of it to your home page, where the additional link equity may provide some SEO benefits to your site. So that’s the spiel — here’s how to do it..

Step 1

Add the following code to your site’s root .htaccess file:

RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)?/?([0-9]+)?/?$
RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)?/?([0-9]+)?/?page

As discussed in the previous section, edit or remove the subdomain to match your own, and then change the to whatever makes sense (e.g., your home page). Test thoroughly using as many different archive/permalink formats as possible.

Step 2

Once the date archives have been redirected via .htaccess, you should go through your theme and remove/edit any date-based archive links and/or code. A typical location for such would be archive.php, archives.php, index.php, and of course date.php if it actually exists. Once your theme is cleaned up, you’re all set, but should keep an eye on any weird activity in your traffic logs. As straightforward as it seems, it’s a big move, and you want to be careful.

Removing year/month/day from single-post permalinks

Removing the year/month/day from your single-post permalinks is another way to improve the SEO integrity of your WordPress-powered site. Here’s the code to do it via .htaccess:

RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$$4

As-is, this technique also removes the subdirectory (/wordpress/), so edit accordingly or remove if not needed. Once in place, this code will change your single-view permalinks from overkill: elegance:

Remember to test thoroughly after making any changes! As always, questions & comments welcome. Thanks for reading :)

Jeff Starr
About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
Digging Into WordPress: Take your WordPress skills to the next level.

19 responses to “Redirect WordPress Date Archives with .htaccess”

  1. Avatar photo

    Hi, I’ve been trying to get this:[4-digit year]/[any thing else]
    to redirect to:[4-digit year]/[any thing else]

    BUT… I only want to redirect stuff that’s in archives, so I can’t do a blanket redirect to /blog/. Ay ideas?


Comments are closed for this post. Something to add? Let me know.
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
BBQ Pro: The fastest firewall to protect your WordPress.
Daylight savings is a complete waste of time and needs to be eliminated.
Got a couple of snow days here in mid-March. Fortunately it's not sticking.
I handle all email in real time as it comes in, perpetually clear inbox for years now.
Added some nice features to Wutsearch search engine launchpad. Now 21 engines!
.wp TLD plz :)
Nice collection of free SEO APIs and user-agent lookups for Googlebot, Bingbot, Applebot, YandexBot, and more.
90% of online customer support is just explaining how to do basic troubleshooting.
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.