Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有.htaccess的CodeIgniter URL_.htaccess_Codeigniter_Url - Fatal编程技术网

带有.htaccess的CodeIgniter URL

带有.htaccess的CodeIgniter URL,.htaccess,codeigniter,url,.htaccess,Codeigniter,Url,大家好,我在为CodeIgniter框架设置.htaccess URL补丁时遇到问题 我在名为“站点”的文件夹中启动了一个站点 =>问题: **此URL工作正常: http://127.0.0.1/sites/home/index/test 我想从URL中删除/index/ 目标URL应如下所示: http://127.0.0.1/sites/home/test 如何获取此URL? 其他信息: 我的自动加载中有URL帮助器,效果很好,下面是我控制器中的代码 class Home extend

大家好,我在为CodeIgniter框架设置.htaccess URL补丁时遇到问题

我在名为“站点”的文件夹中启动了一个站点

=>问题:

**此URL工作正常:

http://127.0.0.1/sites/home/index/test
我想从URL中删除/index/

目标URL应如下所示:

http://127.0.0.1/sites/home/test
如何获取此URL?

其他信息: 我的自动加载中有URL帮助器,效果很好,下面是我控制器中的代码

class Home extends CI_Controller {

public function index($var='')
{
   echo $var; //outputs -> test
}

}
.htaccess
为此,您需要在config/routes.php中添加一个路由:


路由['home/(:any)]=“home/index”

为了通过index()函数参数访问变量,您甚至可以执行以下操作:
route['home/(:any)]=“home/index/$1”哇!这正是我所需要的,它就像一个符咒!这是一个简单而有效的解决方案。谢谢你,伙计!请在下面检查Youn的答案。您将需要创建一条全面覆盖的路线。这将捕获所有到主控制器的请求,并将它们重新路由到index()方法。
RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteBase /sites
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php/$1 [L]