2014-03-07 112 views
0

成熟的一個問題,我不能自己處理,並被迫尋求幫助。 所以......htaccess刪除index.php只有根文件夾

我已經配置.htaccess文件:

RewriteEngine On 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) 
RewriteRule^/%1 [R=301,L] 

此代碼刪除網站上的所有目錄的index.php。我還需要僅在網站根目錄中刪除它。問題是根可以是任何子目錄,如「/」和「/ some_folder /」 是否可以在沒有顯式basedir的情況下執行此操作?

例如,對於CNC我設法讓這麼:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . ./ [L] 

因此,問題: 站點根目錄=httр://site.com/sub/ 刪除的index.php唯一不需要在根目錄下。 腐目錄可能有所不同,在決定應該是沒有明確的basedir

+0

這是我不清楚你想要做什麼。換句話說,輸入是什麼,輸出是什麼? –

+0

site root =httр://site.com/sub_dir/; input = /site.com/sub_dir/index.php; output = /site.com/sub_dir/; input2 = /site.com/sub_dir/sub2/index.php; output2 = /site.com/sub_dir/sub2/index.php; – Belkir

回答

0

您可以使用此規則只從根源消除的index.php:

RewriteCond %{THE_REQUEST} \s/index\.php [NC] 
RewriteRule ^index\.php$/[L,R=301,NC] 
+0

不幸的是,如果目錄是一個子文件夾,它不起作用 – Belkir

+0

但是,只有當它是根目錄或我誤解它時,你纔想刪除index.php? – anubhava

+0

是的,但在我的情況下,根是它躺在htaccess的地方,該網站,可能有htaccess和子目錄,然後轉移到根的子文件夾。 – Belkir

相關問題