Forum Moderators: phranque

Message Too Old, No Replies

301 redirects

Is a htaccess file in each subdirectory a benefit?

         

Broadway

12:40 am on Aug 7, 2010 (gmt 0)

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



In regards to creating 301 redirects in a htaccess file -- for a website with many subdirectories, would it be better to have all of the 301's listed in a single htaccess file in the website root directory, or would it be better form to place the 301's in htaccess files in each of the subdirectories (of course only listing redirects for files in that subdirectory)?

Is one method more work or time consuming for the server, or anything like that?

lammert

1:00 am on Aug 7, 2010 (gmt 0)

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



Apache is searching for .htaccess files in all directories in the tree on each access, so moving all redirects to the root .htaccess file doesn't change the number of file open attempts. But what it does change is the number of unrelated rule parse actions with each URL access. If you have three subdirectories /example1/, /example2/ and /example3/, then each access to a URL in the /example1/ path would also cause the rules dor /example2/ and /example3/ to be parsed. That consumes more time than just parsing the /example1/ rules.

If time is really an issue and you are on a VPS or dedicated server you might instead move all 301 rules to httpd.conf and delete your .htaccess files completely. The httpd.conf file is only read and parsed when Apache starts and the rules are stored in a processed way in memory, allowing much faster rule executing when an URL is accessed compared to .htaccess based rules. The drawback is that rules in httpd.conf can't be changed without restarting the Apache server.

Broadway

2:48 am on Aug 7, 2010 (gmt 0)

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



Thanks. The idea of just having a single file appeals to me (seems easier to manage and keep straight), so I'm glad to hear that's the best for the server too.