htaccess删除index.php和index.php /

时间:2016-01-18 11:58:38

标签: apache .htaccess joomla

我已经谷歌了很多,但我找不到任何规则来从这两种情况中删除index.php:

  1. domain.com/index.php => domain.com
  2. domain.com/index.php/other/stuff => domain.com/other/stuff
  3. 这是我到目前为止所做的事情

    RewriteRule .* index.php [L]
    RewriteCond %{REQUEST_URI}  !(administrator) [NC] #exclude administrator folder
    #RewriteRule ^index.php$ /$1 [R=301] #when this is enable work only first case
    RewriteRule ^(.*)index.php$ /$1 [R=301,L] #when this is enable work only second case
    

    如果我启用这两种情况,则所有请求都会重定向到domain.com

    感谢。

2 个答案:

答案 0 :(得分:0)

首先确保MOD重写为ON。

试试这段代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
希望这有效!

答案 1 :(得分:0)

希望这行得通!

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|assets|robots\
.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]