Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow access to only a single file?

Tags:

apache

I have a apache machine which is serving a .js file. That file should be the only file that need to seen.

I have configured to do so in my apache like this :

<Location /var/www/test/test.js>
    Order allow,deny
    Allow from all
</Location>

The site address is test.in which points to test.js file in /var/www/test directory. That is working fine. But I wish when the user tries to hit test.in/someurl (which is not available) or some other url than test.in need to give an message with 401 error.

How do I do that? Thanks in advance.

like image 272
sriram Avatar asked Dec 10 '12 11:12

sriram


People also ask

Can I share a single file on OneDrive?

Just right-click the file or folder in your OneDrive folder on your computer and select Share a OneDrive link. This will copy a link to your clipboard that you can paste where ever you want to send it. However, these links are set by default to Edit permission.


1 Answers

You misused <Location> - the argument should be URI not the directory path... You should use <Directory> to get the expected behavior.

I would do something like this (you should finetune it, it shows just the principle):

# first deny access to everything
<Location />
 Order Deny,Allow
 Deny from All
</Location>

# then allow access to specific URL
<Location /test/test.js>
 Order Allow,Deny
 Allow from All
</Location>

Have a look on Order directive and one or more of following: Location, LocationMatch, Directory, DirectoryMatch, Files, FilesMatch, etc.

like image 198
Kamil Šrot Avatar answered Nov 08 '22 07:11

Kamil Šrot