2011-10-04 109 views

回答

34

的.htaccess指令apply to that directory, and all subdirectories thereof,所以你應該禁止在你的DocumentRoot訪問,

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

Order deny,allow 
Deny from all 

,並覆蓋,在任何特定的子目錄你想允許訪問,

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

Order allow,deny 
Allow from all 
+5

我們應該做些什麼以防萬一許多子目錄? –

+0

這是一個未經測試的假設,但您只需要在應該可以訪問網絡的任何子目錄中使用第二個'.htaccess' – Matthew

1

Magento的後端嘗試創建sub.mydomain.com的.htaccess文件否認,並在sub.mydomain.com/test允許。

或者您可以從http://sub.mydomain.com/重定向到拒絕子目錄。

8

那麼在根目錄下的.htaccess如何?

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] 

因此,如果 '/測試/' 節目前,還沒有重定向發生......

+0

看起來相當有趣。我不得不承認,我不是很熟悉mod_rewrite。所以我完全不知道[NC]和[R,L]是什麼意思...... –

+3

NC表示不區分大小寫,R =重定向,L =最後(在此之後停止從htaccess應用規則) – SW4

相關問題