开发者

How to exclude .png files from being rewritten via htaccess

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 %{DOCUME开发者_开发问答NT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜