Welcome to WebmasterWorld Guest from 3.85.245.126

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

.htaccess 301 redirects how many is too many?

In other words, how many redirects does it take to affect performance?

     
8:41 pm on Nov 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 30, 2003
posts: 728
votes: 0


We're about to re-launch a very content-heavy site where effectively every URL has changed (this was necessary for technical and IA improvement reasons). There are several hundred 'top' pages that the client is keen to redirect, but there are hundreds more unique pages that could be redirected.

Can anybody speculate about what might be too great a number for Apache to handle gracefully? (Obviously webservers differ too much for a one-size-fits-all answer, but if you have any experience, I'd be happy to hear it...)

-- b

9:51 pm on Nov 24, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 14, 2008
posts:2910
votes: 62


It really depends on how efficient you can be more than anything else... If you can redirect 5000 pages with a single rule because you can pattern match the URLs with a simple pattern, then you can redirect a huge number efficiently.

If you have to redirect each one individually, the answer is probably much less. It really depends on the situation, how many URLs you can match based on 'non-catch all' patterns and some of it will depend on your ability to construct efficient regular expressions. I've redirected over 11,000 pages in less than 10 rules before and not noticed any significant load on the server, but I would not put 11,000 rule in a single file.

10:58 pm on Nov 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Consider putting the rules which redirect many URLs into the server configuration files, where they will be 'compiled' at server restart time. The same rules in .htaccess will run much more slowly, because they will be 'interpreted' on-the-fly for each and every HTTP request.

For the one-URL-at-a-time rules, consider putting them into either individual <Directory> containers in the server config file, or into individual .htaccess files in the specific directories to which they apply; requests to other directories then won't even 'see' these rules.

However, you must be and remain aware of a very important factor: Rules will be processed from 'the top down' -- from the server config files down through each .htaccess file along the filepath to the content to be served. It is critical that *all* external redirects which might potentially apply to a URL be processed before *any* internal rewriting of that URL can take place. If this rule is broken, then an external redirect will 'expose' an internally-rewritten filepath as a URL, and you will have major headaches with search engines as a result. So plan carefully...

As for how many is too many, it's like asking "How long is a piece of string?" The answer depends on your server's raw performance, the number of 'hits' you get, how efficient your redirect code is, and where it is located... As a result, it's quite difficult to even guess the number of directives you might be able to execute without any noticeable performance degradation; Suffice to say that the answer is likely greater than 100 but less than 3000.

However, there's no fundamental difference between Apache module directives parsed in .htaccess files and PHP scripts parsed in the content-handler phase, and many sites have PHP scripts with thousands of lines of PHP code... Just make your code as efficient as humanly possible and hope for the best.

Jim