Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Posts
    40

    .htaccess vs php

    I run a site, and let's say on this site I have two pages, page A and page B.

    When most people go to foo.html, I want to show them page A. But for a small subset of people I want to show page B instead.

    I can implement this in one of two ways:

    1. I can make foo.html a php script that checks which group people are in and then open and print page A or B depending on group.

    2. I can use .htaccess and mod_rewrite to determine which group they are in and redirect them to the correct page. Even better than that, I can make foo.html == page A, and only redirect for people who need to see page B.

    Now, my question is... Which of these is less server intensive? With PHP I have the overhead of loading it as cgi (shared environment, the only way I can do it afaik). I have no idea what the overhead of .htaccess is.

    Which way would you choose to implement this? My first impression would be that .htaccess is faster/more efficient, but not knowing the overhead of mod_rewrite much, I thought I would ask. As a note, there are already other mod_rewrite rules in place, if that matters.

    Any help would be appreciated.

  2. #2
    My *guess* would be .htaccess. BUT! I'd rather ask the hosting provider to enter mod_rewrite rules to httpd.conf rather than in .htaccess.
    Why? Because mod_rewrite works *way* faster when used via httpd.conf.
    There's more info about that at apache.org (if you're interested why).
    Dyslexics Have More Fnu

  3. #3
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Even better than that, I can make foo.html == page A, and only redirect for people who need to see page B.
    This would seem like the fastest way. Depending on how you determine the people that need to see page B, mod_rewrite may not work for you.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    Join Date
    Sep 2005
    Location
    Southern California
    Posts
    179
    I think the performance gain would be negligible, and i would make my decision entirely based on convenience. My instinct is that PHP would be more flexible and easier to implement.

  5. #5
    Join Date
    Jan 2004
    Posts
    40
    I've implemented it both ways (to make sure the .htaccess part would work) on a testing harness.

    This script may at some point be handling 200k page views per day, so even a small performance gain might be useful.

    There isn't any easy way to measure is there?

  6. #6
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Well, ab is one way. It should come with your Apache distribution. (ab = apache benchmark).
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •