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]
I usually use a
RewriteConddirective 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: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: