What does this line in .htaccess do, and when would I need it?
RewriteRule !.(js|css|ico|gif|jpg|png)$ index.php
I’m working with zend and I noticed the .htaccess generated by zend doesn’t have this rule, but I’ve seen a tutorial that has it without explaining why.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
It’s a
RewriteRuleredirecting every request except requests for those file types (js, CSS, icons, GIF/JPG/PNG graphics) toindex.php.It’s so that requests for static resources don’t get handled by index.php (which is generally a good thing, because starting a PHP instance is expensive.)
It is however already handled in the code block below. This part:
Excludes the redirection to
index.phpfor files that physically exist (-s); symbolic links (-); and existing directories (-d).If you use the second block you quote (the one created by Zend), everything’s fine.
Reference in the Apache manual