Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 258
user2394156 Avatar asked Oct 15 '13 12:10

user2394156


1 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>

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.

like image 107
Ilija Avatar answered Nov 15 '22 08:11

Ilija