views:

71

answers:

1

I have a directory on server, from which I only want .JPG files to be served by apache - and apache should deny requests for php, php3, php5 etc files.

What should I write in .htaccess?

I have tried following, first two are giving 500 internal error, third one is not working at all!

 <Directory full-path-to/USERS>
 <FilesMatch "\.(php3?|phtml)$">  
     Order Deny,Allow
     Deny from All
 </FilesMatch>

<LocationMatch "/USERS/.*\.(php3?|phtml)$">
     Order Deny,Allow
     Deny from All
</LocationMatch>


php_flag engine off

Regards,

+4  A: 

How about some mod_rewrite?

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !(\.jpg|\.jpeg)
RewriteRule ^(.*)$ - [F]

This would allow only .jpg or .jpeg files to be served, and everything else would get a 403 forbidden.

davethegr8
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaand this works!!!Thanks a zillion man!
effkay
+1 for an interresting solution. What about side effects of having the RewriteEngine turned on? (I don't know very much about it, that's why I'm asking.)
Tom
Glad it helped. I'm not sure what the side-effects would be, but I have a feeling it would be very small or non-existant.
davethegr8