Forum Moderators: phranque

Message Too Old, No Replies

.htaccess vs. httpd.conf vs. mod_rewrite

Need to make our redirects more efficient

         

caveman

6:32 pm on Apr 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We have something less than 200 redirects on one site. Each redirect goes to a different external site (advertisers and affiliate marketers). We maintain these redirects because it makes our lives easier when we trade out one advertiser for another.

Lately we keep hearing this could slow down our site and the site's traffic is growing rapidly, so it's a concern.

First question: How many redirects are needed before an .htaccess file starts to slow load times, generally speaking.

We have been advised in other forums to move the redirects to an httpd.conf file, since that file only loads once instead of with each page. However, our host like most who offer shared hosting does not allow access to the httpd.conf file. I can't afford dedicated.

So can our issue of slow loads be addressed in any better way than the current .htaccess method? Maybe with mod_rewrite? (which I know next to nothing about, except that we've used it a few times with wildcards to redirect an old site to a new one).

Could/should mod_rewrite be used to manage hundreds of individual redirects, each to a different destination? TIA.

lemat

7:43 pm on Apr 14, 2004 (gmt 0)

10+ Year Member



Because apache has to compare each rule for each served file you should consider the following:

if you want to have redirection www.yourdomain.tld/alamakota to www.otherdomain.tld/something

create a serwer side script (for eg. PHP) named alamakota which will send header("Location: [otherdomain.tld...]

and of course make this script let through PHP engine (ForceType apache directive)

I used to have redirect.php?id=#number# - it grabs URL from database and sends header("Location: $URL")

jdMorgan

1:45 am on Apr 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



caveman,

mod_rewrite in httpd.conf is faster, because it is compiled at server restart and it is native to the server.

mod_rewrite rules in .htaccess files are interpreted for each request: Each page, each image, each script, each CSS file.

One of my .htaccess files has exceeded 35kBytes at times, and it didn't slow things down much. But this site only gets a few thousand hits a day.

PHP is a possible solution, but I think you'll find that mod_rewrite in httpd.conf is faster. An exception would be if you need to process all requests through a tracking script anyway. In that case, you might as well add the redirect in the script, as you have already "paid" for the overhead of starting php and parsing the script.

I should also add that you might want to performance-test the RedirectMatch directive of mod_alias as well.

Jim

caveman

12:08 pm on Apr 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jim, lemat.

The .htaccess file is about 10kB. Maybe this is not worth the bother, since my host for this site won't allow access to the httpd.conf file.

Thanks again.