Location and Directory cause 500 error - apache

I have an .htacces file and I am trying to open up access to a file and folder within a protected folder.
The file is index.php so I do the following:
<Files index.php>
Order Allow,Deny
Allow from All
Satisfy Any
</Files>
This works and give me access to this file. This file requires assets from the assets/ directory. So I try to open that directory up by doing the following:
<Directory "/assets">
Order Allow,Deny
Allow from All
Satisfy Any
</Directory>
But this is giving me a 500 error. Not sure why.

You can't use the <Directory> container inside an htaccess file (which is essentially like the <Directory> container itself). If you want to allow access to assets, then create an htaccess file inassets with just:
Order Allow,Deny
Allow from All

Related

.htaccess limit one folder and one file with one directive

this does not work - I want to limit one folder and one file with one directive to avaoid that I have to add the allowed IP adresses two times.
<Directory .../homes/*/wp-login>
<Files .../homes/*/wp-login.php>
Order deny,allow
deny from all
allow from ...
allow from ...
allow from ...
.
.
.
</Files>
</Directory>
With one directive for the file and another one for the folder it works but then the .htaccess file woul get double size. :-(

Which folder to add a public accessible file in yii-framework?

I need to upload a public accessible file in yii installation which I can access from url. This is domain verification file. I've uploaded it in /frontend/web folder but it's not accessible directly via url mydomain.com/file.txt
As pointed out below, .htaccess file may be preventing this file to be accessible. Can anyone let me know how to write rule in .htaccess file to allow it?
This might help
<Files *.*>
Order Deny,Allow
Deny from all
</Files>
<Files ~ "^index\.php|css|js|.*\.png|.*\.jpg|.*\.gif|.*\.jpeg|.*\.ttf">
Allow from all
</Files>
If you get the following error.
You don't have permission to access /frontend/web/ on this server.
Then, add the following rule in your .htaccess
<Directory "/path/to/frontend/web/">
Options +Indexes
Allow from all
</Directory>
Here the documentation about Apache .htaccess permissions

httpd block access for all file types in a directory but allow access to a single file.

inside my site i have a directory /here/is/the/dir/path
i want to allow access to a single file in a subdirectory
example: test/testfile.xml
but want to deny access to a list of other files (jsp, class, jar, xml )
i have this which i want to place in httpd.conf
<Directory /here/is/the/dir/path >
<FilesMatch "test.xml">
Order Allow,Deny
Allow from All
Deny from None
</FilesMatch>
<FilesMatch "+\.(jsp|class|jar|xml)">
order allow,deny
deny from all
</FilesMatch>
</Directory>
is this the correct way to write this? is there a way to combine my two file match statements into a single statement ?
the stated method has been tested and is working.

How to allow access to only a single file?

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.
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.

apache alias error subfolders access

I have WAMP server 2.2
I created a test php project (2 php files) in my test folder, the test folder is located at: c:\projects\test\
I added an alias to apache, and the conf file is this:
Alias /test "c:\projects\test\"
<Directory "c:\projects\test/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
I added a new folder under test, full path is: c:\projects\test\img
My issue is that I cannot access from http any file located under this folder. Do I have to add some extra line in conf file? What is wrong? I'd like to be able to access any file in any subfolder of my root folder (c:\projects\test).
Thank you.