2016-08-30 82 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]