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?

2 Answers 2


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.

  • I actually use Redirection on a few of our sites, but this one in particular has some other intricate htaccess rules that aren't covered. And honestly, I don't 100% trust that some of the admins wouldn't do something really stupid with it :p
    – Dan Gayle
    Sep 22, 2010 at 16:34
  • Can add some examples of the .htaccess rules you need to use that aren't covered by systems like Redirection to your question?
    – EAMann
    Sep 22, 2010 at 16:40
  • You know what, after looking at it again, it appears that MOST of the rules could be pulled into Redirection. Strange. Someone cleared a bunch of the odd stuff out. (Redirects based on spambot typos, date range redirects, adding or removing slashes, adding or removing camel casing)
    – Dan Gayle
    Sep 22, 2010 at 17:32
  • Be careful with Redirection, it has some issues, see: wordpress.org/support/topic/… Sep 23, 2010 at 8:30
  • I've used Redirection on a few sites and once setup found it very useful! Sep 23, 2010 at 8:46

Here's an answer I wrote that shows how to redirect using PHP from within WordPress:

  • This is good information to know.
    – Dan Gayle
    Sep 27, 2010 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.