.htaccess redirects
November 15, 2010 3:51 PM Subscribe
.htaccess redirects : how many is too many?
I recently moved a client's website from a standard, hand-coded site with many pages, to a document management system with many pages. I couldn't keep the old directory structure, but I wanted to make old links redirect seamlessly to the new system. I resorted to putting a couple dozen "Redirect 301" lines in the .htaccess file in the root directory of the site.
My server manager is telling me that this is not the most efficient way to do this, causes too much memory overhead with the server, and that I should probably find another way to do it.
First, is he right? And second, what's the alternative?
posted by crunchland to computers & internet (6 answers total) 3 users marked this as a favorite
In my experience, the concern over redirects (other than not breaking SEO) is the number in a row -- that is, if you're redirecting page a to page b, which redirects to page c, which redirects to page d, you're doing it
wronginefficiently.However, putting your redirects in an .htaccess file in your root directory is indeed not quite as efficient as putting them in a server configuration file include, as far as I remember. And putting your redirects in a server configuration file include is more efficient (as far as server load is concerned) than every other viable solution, such as redirecting in the header of the document returned from the old location or (shudder) a meta tag redirect. That's because using the server config file (or .htaccess) allows the redirect to be processed before any page is served to the user -- all other solutions require data to be sent to the client, which then processes the redirect.
So, you're almost doing it right, and you should ask the server manager to host the redirects in a config file in the server's config directory.
Oh, and just a datapoint: for many, many years, the major web company I work for had a redirector box -- a single, ancient, Java-powered nightmare -- that contained nothing except tens of thousands of redirect and rewrite rules amassed over the years and maintained (often through multiple document chains) until they were either retired or migrated to a new, faster system that managed the same redirects. That box was not packed with memory or written efficiently, and yet it always responded quickly and never went down on us (until we finally managed to migrate stuff off and retire it.) Also, every single http://domainname/dirname request gets redirected to http://domainname/dirname/ in the same way your rules will be processed. So personally I think that, beyond migrating to an included server config file, there's no way you can make it more efficient and you shouldn't stress about a couple of dozen redirects.
posted by davejay at 4:26 PM on November 15, 2010