我有以下问题。假设我有像
这样的链接 http://localhost/test/index.php/admin
我有以下htaccess:
Options -MultiViews
Options +FollowSymLinks
Options -Indexes
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) $1$2 [R=301,NE,L]
它的作用是从URL中删除index.php。但是,当我输入这样的URL时:
http://localhost/test/abc/blabla/index.php
它继续无限循环。我想要的是在URL中满足另一个index.php时什么都不做。我怎样才能做到这一点?谢谢!
答案 0 :(得分:0)
用以下代码替换您的代码:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} !(^|&)r(&|$)
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ $1$2?r [R=302,NE,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!index\.php/).+)$ index.php/$1 [L,NC]