我想在Codeigniter中从url中删除"index.php" . 我知道如何从基本URL中删除index.php,如 example.com/controller .
但我不知道如何删除子文件夹中的"index.php",如 example.com/folder/index.php/controller
因为我必须在codeigniter中使用不同的项目 . 所以我已经在子文件夹中上传了第二个项目 .
.htaccess
#original
#RewriteEngine on
#RewriteCond $1 !^(index\.php|images|robots\.txt)
#RewriteRule ^(.*)$ index.php/$1 [L]
#modify
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
以上基本网址的程序 . 那么我将在这个程序中更改它在子文件夹上工作 .
4 回答
将此代码写入.htaccess文件中
示例:example.com/folder/index.php/contorller
上面的代码之后无需编写index.php
它正在工作..
在config.php
$config['index_page'] = '';
中更新此变量 . 删除index.php
//找到下面的代码
//删除index.php
步骤:-2转到CodeIgniter文件夹并创建.htaccess文件 .
路径:
步骤:-3在.htaccess文件中写下面的代码
步骤:-4在某些情况下,uri_protocol的默认设置无法正常工作 . 要解决此问题,只需打开位于application / config中的文件config.php,然后查找并替换代码:
//找到下面的代码
//替换为
执行与example.com文件夹完全相同的步骤,从example.com/folder文件夹的基本URL中删除index.php . 也就是说,编辑/创建htaccess,从配置文件中删除index.php等 .