2016-08-30 80 views
0

对不起,如果我重复一些关于.htaccess的讨论。但我没有找到直接回答我的问题。 它们是: 1.我试图从主目录和子目录中的URL中删除index.php。 到目前为止,我得出以下两条规则(一个用于主目录及其他子目录):htaccess中的DirectoryIndex的正则表达式

# removes index.php (in public_html) 
RewriteRule ^index.php$/[QSA,R] 

# removes index.php (in all directories exept public_html) 
RewriteRule ^(.*?)/index\.php /$1 [R=301,R] 

有没有办法用一个共同的规则,使之?

  • 我也有好几个子目录,索引文件与-index结尾不同的前缀: BLA-指数,富指数,前缀指数等等。我想使用某种正则表达式将它们全部作为DirectoryIndex工作。 以下规则删除前缀的index.php

    #removes prefix-index.php (in all directories exept public_html) 
    RewriteRule ^(.*)/(.*)index.php /$1 [R=301,R] 
    
  • 这正是我想要的,但现在我已经403错误,因为 htaccess的说:

    DirectoryIndex index.php 
    

    我已经尝试了不同的规则DirectoryIndex的表达式没有成功。请帮忙!

    P.S.我只能用htaccess的不使用此代码在网站根目录的.htaccess httpd.conf中

    回答

    0

    您可以删除index.php

    DirectoryIndex index.php 
    Options +FollowSymLinks 
    RewriteEngine On 
    
    RewriteCond %{THE_REQUEST} \s(.*)index\.php[?\s] [NC] 
    RewriteRule^%1 [L,R=301,NE]