Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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

Hi @Dan Gayle:

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

share|improve this answer

Your Answer

 
discard

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.
{"cc_re__cc_re__cc_by_sa_3_0": ["sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com?utm_source=stackoverflow.com&amp;utm_medium=site-ui&amp;utm_campaign=footerlink\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>                   with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.11.24.2043\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    WordPress is a trademark of the WordPress Foundation, registered in the US and other countries. This site is not affiliated with the WordPress Foundation in any way.\r\n        "], "copyright__copyright__copyright": ["ks 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.\n\nshare|improve this answer\n\nHi @Dan Gayle:\n\nHere's an answer I wrote that shows how to redirect using PHP from within WordPress:\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}