views:

84

answers:

1

I have the following rule that redirects all traffic to index.php when public folder is visited. How can I modify it to exclude .png files? That means, if /public/something.png is visited, it should render in the browser or should be accessible inside the code when called using an:
"<img src='/public/example.png'>".

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]
+2  A: 

I usually use a RewriteCond directive to specify extensions of static media content that I don't want redirected to a Front Controller. The pipe (|) chars mean "or", so you can add or remove extensions in this rule to work for whichever ones you don't want redirected:

RewriteCond $1 !\.(js|ico|gif|jpg|png|css|swf|mp3|wav|txt|xml)$

Edit

Commenters are correct, if you use that exact line, the $1 needs some context. In your particular case, you could alter it slightly and put it on your index.php RewriteRule line instead, like this:

RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|mp3|wav)$ index.php [NC,L]
zombat
Doesn't `$1` require there to be an expression in front of it (with parens around it) so to grab this data?I don't think you can simply say $1, as there is no data in that register until you say something like `(.+)` first.
Dan Beam
Perhaps I'm just seeing you line out of the overall context, though?
Dan Beam
This doesn't seem to work in conjunction with the above rules i specified.
Vincent
Right, sorry, I just copied the one line. I'll give it an edit.
zombat