Only allow to view images from a folder with simple .htaccess file

Once in a while my beloved hackers upload their shitty files into image folder (basically they use some plugin for image upload). In most cases I will go and clean website. As additional measure to block future attempts, I tend to add small .htaccess file to tell webserver deny access to certain types of files.

First option

Just add the following code to .htaccess file and listed extensions will be restricted:

RewriteEngine On
RewriteRule \.(html|shtml|php|php3|inc)$ http://www.nordichosting.com/ [NC,R=302,L]

and if visitor requests anything with extension html, shtml, php, php3, inc – he or she will be redirected to nordichosting.com. ?

Second option

with this example only listed extensions will be allowed:

RewriteEngine On
RewriteRule !\.(jpg|png|gif|jpeg)$ http://www.golarge.no/ [NC,R=302,L]

Other good .htaccess examples:

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code