Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mod_Rewrite question

    ive started learning mod_rewrite for one of my latest projects.. and came across this statement in yourhtmlsource.com

    --------------------------------------------------------------------------
    Multiple redirects in the same .htaccess file can be applied in sequence, which is what we’re doing here. This rule is added before the one we did above, like so:

    RewriteRule ^products/([0-9][0-9])$ products/$1/ [R]
    RewriteRule ^products/([0-9][0-9])/$ productinfo.php?prodID=$1

    Thus, if the user types in the URL products/12, our first rule kicks in, rewriting the URL to include the trailing slash, and doing a new request for products/12/ so the user can see that we likes our trailing slashes around here.

    ---------------------------------------------------------------------------

    Now thats all fine and dandy, but with a site serving over 500,000 HTTP requests per day, im a little concerned about this. If even, a 4th of my users forgot to type the trailing / after the links , it would force apache to make a new request, which in a high traffic enviorment is not a good situation. All those requests can quickly add up, and degrade server performance.

    Is their a way to match that example URL with or without the trailing / without submitting a new request?

    Thanks.

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Location
    Madison, Indiana, USA
    Posts
    166
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The "new request" this is talking about should not affect your bandwidth. It is an internal request within the Apache server which causes Apache to parse the "new uri" (the one with the '/' added to the end) against the Rewrite rules in your .htacces file.

    The purpose of this rule is to prevent the server from sending the request back to the client as a 404 or 302. It actually cuts down on your badwith usage instead of increasing it.

    That aside, you could also try something like
    Code:
    RewriteRule ^products/([0-9][0-9])$ productinfo.php?prodID=$1 [L]
    RewriteRule ^products/([0-9][0-9])/$ productinfo.php?prodID=$1
    Note: You might want to check the syntax of this, since I'm doing it from memory, but I think the [L] will cause Apache to treat this as the last RewriteRule if it is successful.



    .
    Last edited by hyperbole; 12-03-2005 at 04:46 PM.

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    360
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Quote Originally Posted by Sayian
    Is their a way to match that example URL with or without the trailing / without submitting a new request?
    Adding a ? after the / makes it optional.
    Code:
    RewriteRule ^products/([0-9][0-9])/?$ productinfo.php?prodID=$1


  •  

    Posting Permissions

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