user2394156 user2394156 - 4 months ago 39
Apache Configuration Question

Rewriting only when a file doesn't exist

I've got a .htaccess file as it follows:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L]

I've got this file in my web directory. Is there any way to force this rule to stop rewriting if there's a file?

For example: I've got a css/style.css file but the server returns 404 because the mod_rewrite rule works. If I turn the mod_rewrite off, the file is found.


Yes, there is:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^(.+) - [PT,L]

  RewriteRule ^assets/(.*)$ public/assets/$1 [L]

First block of conditions and the first rule is applied to existing files and folders, and the second rule if an actual rewrite that should happen if there is no file or folder.