删除index.php是有效的,但不适用于index.php


Remove index.php is working but not for index.php?

正如我的标题所说,我成功地从URL中删除了index.php,但显然当我键入"index.php?"时,它不起作用。我在谷歌上搜索了所有内容,但没有发现这个问题。

这是我的.htaccess中的代码(我也在使用CI):

RewriteEngine On
RewriteBase /
RewriteRule ^index.php/(.*)$  $1 [R=301,L] 
RewriteCond $1 !^(index'.php|resources|robots'.txt)    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^www'.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

提前谢谢!

在其他规则之上添加此规则以删除index.php:

# remove index.php
RewriteCond %{THE_REQUEST} /index'.php [NC]
RewriteRule ^(.*?)index'.php$ $1%{QUERY_STRING}? [L,R=302,NC,NE]

您可以将应用程序文件夹从系统文件夹中取出,并使用以下代码:

RewriteEngine On
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

它应该起作用。

并从config/config.php文件中生成enable_query_strings FALSE:

$config['enable_query_strings'] = FALSE;

遵循这个可能会对你有所帮助http://ellislab.com/codeigniter/user-guide/general/urls.html

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