Forum Moderators: phranque

Message Too Old, No Replies

How many redirects is it ok to put in .htaccess?

         

seoArt

2:16 am on Sep 17, 2007 (gmt 0)

10+ Year Member



I'm redesigning one of my sites, and it looks like I will have to put a lot of 301 redirects in an .htaccess file (like 200).

Is that too many? Will it slow down the server response time?

I'm not sure how it works, so I apprecite any advice.

SeanW

12:48 pm on Sep 17, 2007 (gmt 0)

10+ Year Member



It depends on a lot of things -- the nature of the regex, the connection rate, etc.

If you need 200 regexps maybe you should look at a different way of doing things, though. Would RewriteMap help?

Sean

jdMorgan

12:54 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is similar to "How long is a piece of string" in that the answer depends on your site's traffic, the capabilities of your server, and whether it is a dedicated or shared server.

I have almost 2000 lines of code in the .htaccess file of one low-traffic site, and although even one directive in .htaccess does indeed "slow down the server," the performance effect of these 2000 lines is simply not noticeable compared to the disk retrieval time, the HTTP transaction time, and the TCP/IP transmission time.

It is good to pay attention to performance-affecting issues, both in the length of the code and in the efficiency with which it is coded (pay attention to coding techniques and use efficient ones). However, realize that .htaccess code is parsed and executed using very simple optimized processes within Apache, so it is inherently- efficient barring any really-egregious coding techniques. You can consider .htaccess directives as being on par with, say, PHP directives; Many people worry about 200 lines of .htaccess code, and then invoke a 10,000-line PHP script without concern...

Jim

seoArt

8:20 pm on Sep 17, 2007 (gmt 0)

10+ Year Member



Is it something that gets cached by the server? Or is it read every time the directory is accessed?

phranque

11:14 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



reparsed every directory access...

g1smd

11:14 pm on Sep 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure that the most specific redirects come first, and the general later. If you can, make sure the most often used come first, but that isn't often possible.

Study the forum here, to see if there are any ways of making any of the redirects more efficient. Using (.*) in the code often isn't the best way to get things done.

Investigate those.