Redirecting WordPress’ date-based permalinks via Apache.

Snippet for redirecting from date-based permalinks to date-less permalinks on WordPress using Apache.

Follow up to a similar post on Caddy. I am now, instead of self-hosting, using Cloudways — courtesy of a friend (hi!).

This meant moving all my redirects and rewrites from Caddy’s Caddyfile to Apache’s .htaccess.

My host is using Apache 2.4 and let’s assume I do not have access to the VirtualHost configuration. I’ll use the RedirectMatch directive here as it super similar to Redirect except for allowing RegEx.

RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)/$ /$1/

RewriteRule, for whatever reason, does not seem to work on my host even when it should. I posted about this on SmallCamp, but to me, it looks like it might be different ways of doing the exact same thing. So I’ll settle with RedirectMatch for now.

Photo by Artem Podrez from Pexels.


Comment via email.