2014-09-23 86 views
1

我已經將mi站點文件移動到子文件夾並使用.htaccess重定向到它,但我需要拒絕直接訪問此文件夾或子文件夾。Mod重寫重定向文件夾爲root並使用文件夾作爲根

在.htaccess得到這個:

<IfModule mod_rewrite.c> 

    Options +FollowSymlinks 
    RewriteEngine On 
    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteRule^http://%1%{REQUEST_URI} [R=301,L] 

    # Block access to hidden files and directories. 
    # This includes directories used by version control systems such as Git and SVN. 
    RewriteCond %{SCRIPT_FILENAME} -d [OR] 
    RewriteCond %{SCRIPT_FILENAME} -f 
    RewriteRule "(^|/)\." - [F] 

    # Deny direct access to this directory or any sub-directory 
    RewriteRule ^site/(.*)$/[R=301,NC,L] 

    # Do not apply redirection to these folders/files for compatibility 
    RewriteRule ^(subdir1|subdir2)(/|$) - [L,NC] 
    RewriteRule ^robots.txt - [L,NC] 

    # root from sub-directory 
    RewriteRule ^(.*)$ site/live/$1 [L,QSA] 

</IfModule> 

當我去:

htt://domain.com/site -> htt://domain.com (CORRECT REDIRECTING) 
htt://domain.com/site/unexist-> htt://domain.com (CORRECT REDIRECTING) 
htt://domain.com/site/live -> htt://domain.com/site/live/ (NOT REDIRECTING HERE!) 

在現場/現場存在其他的.htaccess一些重寫規則。這可能是問題嗎?

<IfModule mod_rewrite.c> 

    RewriteRule ^about-us$ about.php 
    RewriteRule ^privacy$ privacy.php 
    RewriteRule ^oauth$ index.php 

</IfModule> 

DirectoryIndex index.php 

# Custom error messages/pages         
ErrorDocument 404 /404.php 
ErrorDocument 403 /403.php 
+0

不'/網站/現場/'有其他的.htaccess? – anubhava 2014-09-23 16:14:39

+0

@anubhava是的它確實,我已經更新了更多的細節問題 – 2014-09-23 16:20:59

回答

0

有這樣的代碼在/site/live/.htaccess

DirectoryIndex index.php 

# Custom error messages/pages         
ErrorDocument 404 /404.php 
ErrorDocument 403 /403.php 

<IfModule mod_rewrite.c> 

    RewriteEngine On 

    # remove /site/ from URL 
    RewriteCond %{THE_REQUEST} /site/(\S+) [NC] 
    RewriteRule^/%1 [L,R=302,NE] 

    RewriteRule ^about-us$ about.php 
    RewriteRule ^privacy$ privacy.php 
    RewriteRule ^oauth$ index.php 

</IfModule> 
+0

謝謝@anubhava,差不多工作。我必須從'RewriteRule^/%1 [L,R = 302,NE]'中刪除%1,因爲它被重定向到/活巫婆不存在(404) – 2014-09-23 16:45:34

+0

好,那麼你想重定向' http:// domain.com/site/live'到? – anubhava 2014-09-23 16:48:56

+1

我的意思是生活的規則不存在,雖然目錄確實存在,但我不能從「http:// domain.com」以外的地方看到該網站。現在它將http:// domain.com/site/live重定向到http:// domain.com,這沒關係。 – 2014-09-23 16:54:55