mod_rewrite: don't touch files that actually exist

Discussion in 'Apache' started by methomps, Sep 6, 2009.

  1. #1
    Hi guys, I'm having a bit of trouble with my .htaccess file. I have it setup to funnel everything to index.php, but it is not supposed to do this for requests to files that actually exist (like my css). However, given that some of my session variable tracking page views jumps by 2-6 every page load, I suspect it is not working properly.

    What am I doing wrong?

    RewriteEngine on
    
    # Do not rewrite requests for files and directories that exist
    # This means you can still place images, javascript, and css
    # in /home/youraccount/yourdomain.com/ directory (or sub-directories)
    
    RewriteCond %{REQUEST_FILENAME} -f
    # RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule .* - [last]
    
    # Now rewrite every other request to index.php
    
    # Sends: http://www.yourdomain.com => http://www.yourdomain.com?__controller=Index&__action=Index&__params=
    RewriteRule ^/?$ index.php?__controller=Index&__action=Index&__params= [QSA,L]
    
    # Sends: http://www.yourdomain.com/Members => http://www.yourdomain.com/index.php?__controller=Members&__action=Index&__params=
    RewriteRule ^([^/]+)/?$ index.php?__controller=$1&__action=Index&__params= [QSA,L]
    
    # Sends: http://www.yourdomain.com/Members/List => http://www.yourdomain.com/index.php?__controller=Members&__action=List&__params=
    RewriteRule ^([^/]+)/([^/]+)/?$ index.php?__controller=$1&__action=$2&__params= [QSA,L]
    
    # Sends: http://www.yourdomain.com/Members/List/Sort/FirstName/Dir/Asc => http://www.yourdomain.com/index.php?__controller=Members&__action=List&__params=Sort/FirstName/Dir/Asc
    RewriteRule ^([^/]+)/([^/]+)/(.*)/?$ index.php?__controller=$1&__action=$2&__params=$3 [QSA,L]
    Code (markup):
    This code:

    RewriteCond %{REQUEST_FILENAME} -f
    # RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule .* - [last]
    Code (markup):
    is intended to tell stop execution of any other rules if the file actually exists, but it doesn't appear to be doing that.
     
    methomps, Sep 6, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try changing [last] to [L]
     
    premiumscripts, Sep 7, 2009 IP
  3. methomps

    methomps Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmm, problem persists. Any other ideas?
     
    methomps, Sep 8, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, you could just add the reverse condition to all other rewriterules as a last resort..

    RewriteCond %{REQUEST_FILENAME} !-f
     
    premiumscripts, Sep 8, 2009 IP
  5. methomps

    methomps Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's a good idea and should work, but does not. Thanks for your help, though.
     
    methomps, Sep 11, 2009 IP