htaccess删除index.php和index.php/ [英] htaccess remove index.php and index.php/

查看:59
本文介绍了htaccess删除index.php和index.php/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google上搜索了很多,但是找不到从这两种情况下删除index.php的任何规则:

I've google a lot but I can't find any rule to remove the index.php from both cases:

  1. domain.com/index.php => domain.com
  2. domain.com/index.php/other/stuff => domain.com/other/stuff

这是我到目前为止所做的

Here is what I've done so far

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

If I enable both cases all requests are redirected to domain.com

谢谢.

推荐答案

希望这行得通!

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

这篇关于htaccess删除index.php和index.php/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆