How to release a protected sub-directory with . htaccess?

Asked

Viewed 4,331 times

7

I have a .htaccess in my test environment developed in Cakephp and . htaccess has authentication so that no one can access it.

Now I need to release a site directory, actually a Cakephp plugin, I need anyone to have access without authentication.

<Directory /home/meusite/app/webroot>
  AuthType Basic
  AuthName "Ambiente de Desenvolvimento Teste"
  AuthUserFile /home/user/.htpasswd
  Require valid-user

  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

Question

How can I release a subdirectory from a directory protected by .htaccess above presented?

  • It wouldn’t be more interesting instead of treating it in . htaccess you create an authentication system in Cakephp?

  • 1

    You could post the code you’re using to block access?

  • 1

    First, you should post your . htaccess to understand how you are doing the blocking.

  • @Kennyrafael does not need, as it is a testing environment only. The production environment is operating normally, and the . htaccess is faster to be done. My htaccess code is in question.

2 answers

4


Add to configuration file (usually the httpd.conf):

Note: <Directory ...>...</Directory> not if added directly to the file .htaccess

<Directory /path/to/dir/protected/unprotected>
     Satisfy Any
</Directory>

Source: @atonyc.

  • Even in cakephp it works like this?

  • 2

    These settings are from Apache.

  • 2

    I think the idea is to create a file .htaccess in the root of the directory that should be without password protection and apply in that file the contents of the reply.

  • Unfortunately it didn’t happen... I tried to put it directly on the sites-available server, and tbm tried to put it on. htaccess in the directory I wanted without protection. Could it be something from Cakephp, folder structure, or something like?

  • @Artur Directory does not work with .htaccess, you have to configure in httpd.conf, as Caleb has mentioned, add to configuration file, I’ll edit to make it clearer.

2

Add the following settings

SetEnvIf Request_URI ^/{nomedosite}.*$ noauth=1
Allow from env=noauth
Satisfy any

Change the {dosite} to the path you expect to see in the URL.

Your . htaccess would look like this

for /home/meusite/app/webroot/. htaccess

<IfModule mod_rewrite.c>
  AuthType Basic
  AuthName "Ambiente de Desenvolvimento Teste"
  AuthUserFile /home/user/.htpasswd
  Require valid-user

  SetEnvIf Request_URI ^/meusite.*$ noauth=1

  Options Indexes FollowSymLinks MultiViews
  #AllowOverride All
  #Order Deny,Allow
  Satisfy any
  Deny from all
  Allow from env=noauth

  # Aqui vem as configurações do .htaccess padrão do CakePHP
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

There are other htaccess outside the webroot folder, stay tuned for this.

If you want to list the files within the released folder add the code below that causes the htaccess rules to be ignored for the specified folder.

RewriteRule ^meusite.*$ - [PT]

Source: https://stackoverflow.com/questions/8978080/htaccess-exclude-one-url-from-basic-auth

Browser other questions tagged

You are not signed in. Login or sign up in order to post.