Exlude Real Directories From Mod_Rewrite

Discussion in 'Site & Server Administration' started by fireflyproject, Feb 25, 2009.

  1. #1
    I'm looking for a way to exclude actual directories from mod_rewrite.

    For example, at present my URL's look like this:
    http://www.domain.com/category-name/

    This it being rewritten to pass the category-name on to a PHP script.

    However, if the user tries to go to a folder inside the main area, it's not allowed because right now everything is being considered 'rewritten' by the server if it's not just a file.

    Here is what my .htaccess looks like right now.

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([a-zA-Z0-9\-]+)/?$ sites.php?cat=$1

    Thoughts please?
     
    fireflyproject, Feb 25, 2009 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-zA-Z0-9\-]+)/?$ sites.php?cat=$1
    Code (markup):
    The above only allows the rewrite rule to run if you are not referencing a file for folder that actually exists.
     
    tolra, Feb 26, 2009 IP