正如我的标题所说,我已成功从网址中删除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]
提前谢谢!
答案 0 :(得分:1)
在其他规则之上添加此规则以删除index.php:
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ $1%{QUERY_STRING}? [L,R=302,NC,NE]
答案 1 :(得分:0)
您可以将应用程序文件夹从系统文件夹中取出并使用以下代码:
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
答案 2 :(得分:0)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]