2009-02-06 24 views
0

我需要有一個的.htaccess重寫規則重定向到一個腳本在子目錄下的根,但僅限於任何文件/在該子目錄目錄...的.htaccess重定向到腳本子目錄

/ 
/subdir/ 
    /index.php 
    /somedir/ 
    /anotherdir/ 

對於上面的結構,我希望任何瀏覽到/ subdir的人轉到/subdir/index.php,以及任何去/ subdir/somedir/to /subdir/index.php等的人...

但是,他們去根目錄。他們應該呆在那裏...我已經嘗試將一個.htaccess文件放在/ subdir中,並在重寫規則上進行了一系列的嘗試,但目前爲止沒有任何工作。

更新:我不是說只是/somedir/需要重定向OT的index.php,但/子目錄/需要的任何子目錄是重定向...腳本太多,但顯然不是/subdir/index.php

對不起,我之前並不清楚。

回答

0

如果我理解你的問題,需要發生的,如果有人去/子目錄/ somedir(重定向他們回到index.php文件

如果是這樣的話,這應該工作的唯一實際重定向,放在/.htaccess:

redirect /subdir/somedir/ /subdir/ 
0

如果你只是想內部重定向,試試這個mod_rewrite例如:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/subdir/somedir/index\.php 
RewriteRule ^subdir/somedir/ subdir/index.php [L] 

對於外部重定向,只需添加R標誌(帶有可選的重定向狀態碼:R=xxx;默認:302):

RewriteRule … [L,R=xxx]