我怎样才能避免codelgniter中的URL中的index.php

shi*_*een -5 php codeigniter

我正在使用apache服务器,我需要从uri中删除index.php

The*_*pha 5

打开config.php并替换

$config['index_page'] = "index.php" by $config['index_page'] = ""
Run Code Online (Sandbox Code Playgroud)

在.htaccess文件中添加

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

在某些情况下,uri_protocol的默认设置无法正常工作.要解决这个问题,只需在config.php中替换即可

$config['uri_protocol'] = "AUTO" by $config['uri_protocol'] = "REQUEST_URI"
Run Code Online (Sandbox Code Playgroud)