CodeIgniter Forums
.htaccess not allowing image files to be displayed - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: .htaccess not allowing image files to be displayed (/thread-19123.html)



.htaccess not allowing image files to be displayed - El Forum - 05-28-2009

[eluser]80onelove[/eluser]
I'm having some issues getting my .htaccess to work correctly (I think).

I'm using the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|uploads)
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>


I have files in multiple formats stored in the "uploads" folder... files like .txt and .php display in plain text, while .doc files are downloadable. However, trying to access image files by http (e.g., http://www.mysite.com/uploads/46.jpg) results in a 404 error.

Any ideas on how to correct this?


.htaccess not allowing image files to be displayed - El Forum - 05-28-2009

[eluser]louis w[/eluser]
Add this before the RewriteRule

Code:
RewriteCond %{REQUEST_FILENAME} !-f

It says "if this is a request to a file which exists on the server, don't continue"


.htaccess not allowing image files to be displayed - El Forum - 05-28-2009

[eluser]80onelove[/eluser]
Great, thanks for the reply.

I actually fixed the problem without using the suggested RewriteCond... turns out the files were being written to the uploads folder as read-protected. I just chmodded everything and now it works perfect.

Thanks for the help.


.htaccess not allowing image files to be displayed - El Forum - 05-28-2009

[eluser]louis w[/eluser]
Ahh yes, it should have worked without it. I missed the 'uploads' exception which you already had.

It would be a good idea to add it anyway. That way when you start to add js, css, or a favicon to your site you won't run into the same problem.