Overwrite only when the file does not exist

I have a .htaccess file:

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

I have this file in my web directory. Is there a way to make this rule stop rewriting if there is a file?

For example: I have a css / style.css file, but the server returns 404 because the mod_rewrite rule works. If I disable mod_rewrite, the file will be found.

+4
source share
2 answers

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]
</IfModule>

The first block of conditions and the first rule apply to existing files and folders, and the second rule, if the actual rewriting should occur, if there is no file or folder.

+6
source

The loan goes http://amandine.aupetit.info/135/apache2-mod_rewrite/

%{REQUEST_FILENAME} , :

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d

!-f, , .

+6

All Articles