Welcome to WebmasterWorld Guest from 3.80.4.76

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

a rewrite question

     
2:42 pm on Nov 11, 2003 (gmt 0)

New User

10+ Year Member

joined:Oct 20, 2003
posts:8
votes: 0


Hi,

I have a website where I am doing a lot of mod_rewriting. As such it works fine (just about every single page request is a .html url being rewritten to a php script that draws from mysql). The server is an almost dedicated box (I have a few low traffic sites there as well), Pentium III 733 and it has atleast 30,000 daily pageviews (probably 50,000). Everything runs well, very quick response times.

Now my question is, where I should do my mod_rewriting for best performance. At this time I have 8+ directories that contain a .htaccess that does the mod_rewrites for the directory; ie. in directory x: I might redirect ^[a-z]+.html$ to /scripts/page.php?section=x&p=$1. I am wondering though.. Should I instead delete all those directories and do it all via a number of rewrite rules in a single .htaccess at public_html/? ie. for directory x ^x/[a-z]+.html$ to /scripts/page.php?section=x&p=$1 etc. In short it is: ONE big .htaccess (more rules to check with each hit) for all rewrites/error page definitions etc. rather than one in each directory(less rules to check)?

4:09 pm on Nov 11, 2003 (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


beowulfdk,

Welcome to WebmasterWorld [webmasterworld.com]!

The most efficient approach will be to try to achieve the following:

  • Place RewriteRules which affect only a subset of your files into a subdirectory containing only those files. (Examples might be images or javascripts.)

  • Place RewriteRules which apply to all or almost all files on your site into your Web-root-level .htaccess file.

  • As implied by #1, arrange your files into subdirectories based on filetype, access restrictions, and cacheability considerations, and apply RewriteRules as appropriate.

    Of course, this is much easier to do with a new site design, when you can plan ahead.

    Additionally, those RewriteRules which apply to most files and which are not likely to change can be placed in httpd.conf if you have access to the server configuration. Directives placed in httpd.conf are compiled on server restart, rather than being interpreted on a per-request basis. Therefore, they are processed much more efficiently.

    Jim

  • 4:30 pm on Nov 11, 2003 (gmt 0)

    New User

    10+ Year Member

    joined:Oct 20, 2003
    posts:8
    votes: 0


    jdMorgan,

    Good to hear that :) Based on what you are saying I believe I have a fairly optimized design already, except files are not ordered by file types but by which sections they belong in- it is important for me to have a site directory structure that is fairly human-readable :)

    4:38 pm on Nov 11, 2003 (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


    > The most efficient approach

    Of course, efficiency is only one concern... Maintainability is another. :)

    Everyone must choose a comfortable balance between these and other factors.

    Jim

    5:16 pm on Nov 11, 2003 (gmt 0)

    Full Member

    10+ Year Member

    joined:Feb 5, 2002
    posts:333
    votes: 0


    sorry if i show ignorance but can't anything that can be done in .htaccess be also achieved in httpd.conf?

    i thought you could develop rewrite rules and apache directives in .htaccess and then move them into httpd.conf.

    5:26 pm on Nov 11, 2003 (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


    incywincy,

    Yes, you can, IF you have access (priveleges) to modify httpd.conf, and IF the "design" of your code is stable and not likely to change. However, the great majority of Webmasters do not have access to httpd.conf, thus leading to the popularity of .htaccess.

    The original post mentioned only .htaccess, so the thrust of my reply was to .htaccess, but I did mention httpd.conf as a final note in my first reply.

    Do you have a question about what is posted here, or are you just commenting on the use of httpd.conf?

    Jim

    8:33 am on Nov 12, 2003 (gmt 0)

    Full Member

    10+ Year Member

    joined:Feb 5, 2002
    posts:333
    votes: 0


    soory jim, i was just questioning my own understanding, i thought that if there was a performance issue then httpd.conf is the best solution whereas with respect to convenience (minimising downtime etc) then .htaccess is the way to go. i suspect that to get the best of both worlds then a bit of both is best.
     

    Join The Conversation

    Moderators and Top Contributors

    Hot Threads This Week

    Featured Threads

    Free SEO Tools

    Hire Expert Members