Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 614
Owan Avatar asked Feb 11 '12 01:02

Owan


People also ask

How do I deny access to my site with an .htaccess file?

htaccess IP deny access. To deny access to a block of IP addresses, simply omit the last octet from the IP address: deny from 123.456. 789.

How do I restrict htaccess?

htaccess, IP deny rules must be created. These rules can be configured to block all users or specific users (based on their IP address) from accessing website resources. You can also use . htaccess to block a domain, deny access to certain file types, specific files (for example, configuration files), and more.


1 Answers

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.

like image 76
Book Of Zeus Avatar answered Nov 10 '22 01:11

Book Of Zeus