WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
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 '10 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 '10 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 '10 at 17:32
Be careful with Redirection, it has some issues, see: wordpress.org/support/topic/… – MikeSchinkel Sep 23 '10 at 8:30
I've used Redirection on a few sites and once setup found it very useful! – Adam Dempsey Sep 23 '10 at 8:46

Hi @Dan Gayle:

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

share|improve this answer
This is good information to know. – Dan Gayle Sep 27 '10 at 16:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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