Centos – .htaccess enabled, but not working

.htaccesscentos

I been having some very frustrating issues with getting .htaccess to work on my new server. I'm not very experienced in managing a server, but I've spent the last three days pouring over documentation and every resource I can get my hands on.

I've attempted to try a very basic application of .htaccess, and yet it fails to give the expected results. I've setup a test directory. Immediately within this directory is an .htaccess file with the following command:

deny from all

If I'm not mistaken, this should deny access to /test, but it doesn't. It just sits there allowing anybody to view the contents. I've made a readable copy of the .htaccess available in the same directory for anybody wanting to see exactly what is going on in my .htaccess.

What could be wrong with my server/configuration? The server is running CentOS.

Response to Dom

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

As suggested, I changed this to AllowOverride All, and then restarted my server:

service httpd restart

But received the following message:

Syntax error on line 347 of /etc/httpd/conf/httpd.conf:
AllowOverride not allowed here [FAILED]

Line 347 is the last line below:

# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid.  This usually means that 
# ~useridllowOverride controls what directives may be placed in 
# .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

Best Answer

Do you have AllowOverride All in your Virtualhost configuration ? if you have a AllowOverride None, the .htaccess file is not read, so it will not be used. And right,

deny from all

alone forbidden the connection to the folder. And don't forget to reload apache