I've the next rewrite rules:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  # Route all URLs to dispatch.php.
  RewriteCond %{REQUEST_URI} !media/
  RewriteRule ^(.*)$ dispatch.php [L]

  #Route requests to /media/* to /project/media/*
  RewriteRule ^media/(.*)?$ project/media/$1 [L]

</IfModule>

Things are rewritten to dispatch.php unless of course the URI begins with media/ by which situation it'll rewrite the URI to project/media/*. Everything works fine and when I navigate to example.com/media/css/style.css the stylesheet it offered. Basically navigate to example.com/media/css/ a 403 Forbidden error is distributed. Perfect!

However, Basically navigate to example.com/media/css (missing the trailing '/') then your URL within the location bar is rewritten to example.com/project/media/css and also the request is handled by dispatch.php. How do you stop this behavior from happening? I wish it to be handled by dispatch.php but without projects/ being put into the URL.

Solved: The issue was because of mod_dir redirecting the Web addresses which had no trailing slash. This led to the place because it seems on disk getting used for that redirect meaning the subfolder (project) was appended towards the URI. The ultimate .htaccess which i used is the following:

Options +FollowSymLinks +MultiViews -Indexes
Options -Indexes

<IfModule mod_dir.c>
  DirectorySlash Off
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  #Add trailing slashes
  RewriteCond %{REQUEST_URI} !(.*)/$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ $1/ [R=301,L]

  #Route requests to /media/* to /project/media/*
  RewriteRule ^media(/.*)$ project/media$1 [L]

  # Route all URLs to dispatch.php.
  RewriteCond %{REQUEST_URI} !^media/(.*)
  RewriteRule ^(.*)$ dispatch.php [L]

</IfModule>

The brand new .htaccess does just like before in addition to:

  • Hinders mod_dir.
  • Adds trailing slashes towards the URI by using a RewriteRule.

You can clearly block individuals directory web addresses along with other rewrite rules.

Or... You should use DirectorySlash to show from the redirect.

http://httpd.apache.org/docs/2.0/mod/mod_dir.html