从 url codeigniter 中删除 index.php 的步骤:
配置更改:转到“application/config/config.php”
找到下面的代码:
$config['index_page'] = 'index.php';
替换为以下代码:
$config['index_page'] = '';
.htaccess 更改:如果您没有任何 htaccess,请创建新的并将其放在您的根目录中。
注意:如果您在子目录中有 codeigniter,请将 RewriteBase / 更改为 RewriteBase /subdir/
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
现在打开您的网站页面,您会发现没有 index.php 的干净 url。所以你的所有网址看起来像http://example.com/controller/method。现在对 index.php 的任何 HTTP 请求都将被视为对 index.php 文件的请求。
如果仍然存在问题:需要再应用一项配置更改。
转到“应用程序/config/config.php”
找到下面的代码
$config['uri_protocol'] = 'AUTO';
用下面的代码替换
$config['uri_protocol'] = 'REQUEST_URI';
现在您已经完全完成了从 url codeigniter 中删除 index.php 并在 codeigniter 中获取干净的 url。