2014-03-07 115 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

相关问题