I have a webproject. Inside the web projects are several directories. I want only the web directory to be avilable to all.

I don't have access to change the vhost as this is for an internal intranet app.

I can however create a .htacess file. I know very little about htaccess files but I do believe that by creating one I can restrict web facing access to specific folders. Which brings me to my question.

I'm looking to do is restrict public access to only the web folder via the content in the htaccess.

  .. web -- allow access to all
  .. application -- no public access
  .. library -- no public access
  .. other folder -- no public access
  .. other folder etc -- no public access
  • 1
    Welcome to Serverfault. When you ask questions here, please take a moment to read your query again and supply all relevant details: that makes andwering your question all the easier. In your case, you're asking for instructions on how to configure .htaccess but fail to provide the content of the file. – Stephane May 2 '13 at 9:16
  • @Stephane this is a geniuine question and a cry for help at the same time. I do believe it would be a useful for others. I have re-worded the question and I hope this has addressed any confusion. I would like to point out that the reason there isn't content for the htaccess file is because I don't know what to put in it? – Robbo_UK May 2 '13 at 9:45
  • When you say "no public access", does that mean that you want access with a password, or that you don't want access at all. In other words, does "public" mean "the general public" or does it mean "anyone/everyone"? – Moshe Katz May 12 '13 at 17:41
  • no web access at all. – Robbo_UK May 13 '13 at 8:50

You can just put a .htaccess in every Directory you don't want to get accessed with this content:

Order deny,allow
Deny from all

Do you have any .htpasswd files on your server? This should be sufficient

# password protection allowing multiple resources
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null 
Require valid-user
# allow public access to the following resources
SetEnvIf Request_URI "(path/to/directory_01/)$"         allow
SetEnvIf Request_URI "(path/to/directory_02/)$"         allow
SetEnvIf Request_URI "(path/to/file\.php)$"             allow
SetEnvIf Request_URI "(path/to/file\.html)$"            allow
SetEnvIf Request_URI "(path/to/another/resource/)$"     allow
SetEnvIf Request_URI "(path/to/yet/another/resource/)$" allow
Order allow,deny
Allow from env=allow
Satisfy any
  • if I put that in the projectRoot folder will it disable all apart from the ones listed with allow? – Robbo_UK May 2 '13 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.