Using WP rather than .htaccess to redirect pages/posts

I run a site with over 100 specific redirects in the htaccess for legacy html files that were subsequently brought into WP. There are also rules for pages within a date range to redirect to the home page, and all sorts of other nasties.

Given that WP handles redirects and permalinks internally, and without using a plugin, what would be the best way to programatically redirect these links and keep my .htaccess file clean?

Related posts

Leave a Reply

2 comments

  1. The best way to “programatically redirect these links and keep [your] .htaccess file clean” would actually be with a plugin. I know you stated “without using a plugin,” but you’ll get the same functionality from a plugin that you would if you wrote the code yourself. And, considering how non-user-friendly the WP rewrite scripts are, I strongly suggest you don’t try to write it yourself (I’m an experienced WP developer and I still have trouble with the clanky rewrite engine).

    So if you’re willing to go with a plugin, I recommend Redirection.

    Redirection has a very intuitive UI that allows you to create, display, and manipulate all of your custom redirects. It also keeps track of any 404 errors your site generates by mistake. I use Redirection on my site to redirect legacy links from my ancient static site to the new dynamic WordPress links. I’ve also used it on several client sites after helping them migrate to WordPress.