On apache how do I allow access to only to a single file?
8,117
The Location
directive matches URIs, not directly related to files on the filesystem. I suggest to use Directory
and Files
instead, like this:
<Directory "/var/www/test">
Order deny,allow
Deny from all
<Files "test.js">
Order allow,deny
Allow from all
</Files>
</Directory>
Related videos on Youtube
Author by
sriram
Updated on September 18, 2022Comments
-
sriram over 1 year
I have a apache machine which is serving a
.js
file. That file should be the only file that need to seen.Edit:
I have configured to do so in my apache like this :
<VirtualHost *:7090> ServerAdmin [email protected] DirectoryIndex test.js DocumentRoot /var/www/test ServerName test.in </VirtualHost> <Location /var/www/test/test.js> Order allow,deny Allow from all </Location>
The site address is
test.in
which points totest.js
file in/var/www/test
directory. That is working fine. But I wish when the user tries to hittest.in/someurl
(which is not available) or some other url thantest.in
need to give an message with401
error.How do I do that?
-
Nils over 11 years"points to" is what? A symlink in the filesystem, a redirect, a rewrite?
-
Nils over 11 yearsI still don
t get it.
DocumentRoot` can point to a directory. Not to a file... -
sriram over 11 years@Nils: I have edited my question and added the code which I used to serve the file
-
-
sriram over 11 yearsNope now I cant even able to access the
test.in
. I getforbidden
error! -
gertvdijk over 11 years@sriram That was exactly your request if I read correctly. "That file should be the only file that need to seen." So all other files including the default index files should not be accessible, right?
-
sriram over 11 yearsya but
test.in
should be given access to the filetest.js
. But now I couldn't be able to do that. -
ravi yarlagadda over 11 years@gertvdijk
<Files>
can't have directory paths - try<Files "test.js">
within the<Directory>
block? -
sriram over 11 yearsStill this doesn't worked@!