2011-10-04 19 views

risposta

34

direttive .htaccess apply to that directory, and all subdirectories thereof, così si dovrebbe impedire l'accesso nella tua DocumentRoot,

http://sub.mydomain.com/.htaccess:

Order deny,allow 
Deny from all 

E ignorare che in ogni sottodirectory specifiche che si desidera consentire l'accesso a,

http://sub.mydomain.com/test/.htaccess:

Order allow,deny 
Allow from all 
+5

cosa dovremmo fare nel caso in cui di molte sottodirectory ?? –

+0

Questa è un'ipotesi non testata, ma hai solo bisogno di quel secondo '.htaccess' in qualsiasi sottodirectory che dovrebbe essere accessibile dal web – Matthew

1

Cercate creare file .htaccess nella sub.mydomain.com per nega e in sub.mydomain.com/test per consentire.

Oppure è possibile reindirizzare da http://sub.mydomain.com/ per negare la sottodir.

8

Che ne dici di uno .htaccess nella directory principale, con le seguenti linee?

RewriteEngine On 
# check if request is for subdomain 
RewriteCond %{HTTP_HOST} ^sub.mydomain.com$ [NC] 
# check if 'test' isnt part of request 
RewriteCond %{REQUEST_URI} !^/test/?(.*)$ [NC] 
# if subdomain and no 'test' part, redirect to main domain... 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R,L] 

Quindi, se la sezione '/ test /' è presente, nessun reindirizzamento avviene ...

+0

sembra piuttosto interessante. Devo ammettere, non ho molta familiarità con mod_rewrite. Quindi non ho assolutamente idea di cosa significhi [NC] e [R, L] ... –

+3

NC significa case insensitive, R = redirect, L = last (smetti di applicare regole da htaccess dopo questo) – SW4

Problemi correlati