Monday, June 4, 2012

Using .htaccess to restrict access to files


I have 2 domains hosted on the same account but I want to restrict the second one to not access files.



I have abc123.com and zyx987.com.



In my php I do everything I need to display the domain name and template based on the domain but I want only the /download files to be accessed from abc123.com.



The download folder has files like: file1.pdf or file2.zip.



I tried the 'deny from all' but this didnt work since the other domain is blocked too.



Is there another way?


Source: Tips4all

1 comment:

  1. Here's what you have to do. Put this in your .htaccess

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(www.)?zyx987.com$
    RewriteRule ^download - [F]


    This will block any request like:

    /download/
    /download/file1.jpg
    /download/another/file.zip


    and give a permission denied.

    ReplyDelete