Php 在CodeIgniter中使localhost/调用控制器

Php 在CodeIgniter中使localhost/调用控制器,php,codeigniter,mod-rewrite,url-rewriting,Php,Codeigniter,Mod Rewrite,Url Rewriting,我使用codeigniter并使用.htaccess将localhost/index.php/some_class重写为localhost/some_class 如何让localhost/本身调用某个控制器?正如在localhost中一样,它将是一个类,localhost/some_func 编辑:这是我当前的。htaccess: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt|css) RewriteRule ^

我使用codeigniter并使用
.htaccess
localhost/index.php/some_class
重写为
localhost/some_class

如何让
localhost/
本身调用某个控制器?正如在localhost中一样,它将是一个类,
localhost/some_func

编辑:这是我当前的。htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L] 

您想编辑application/config/routes.php

$route['default_controller'] = "some_class";
通过更改默认的\u控制器,这将调用某个\u类的索引函数。如果my_函数属于某个_类,则无法使用此方法调用localhost/my_函数

编辑:

我看错了你的帖子,你想编辑你的htaccess文件,将所有内容重定向到某个类。如果你发布你的.htaccess,我们可以帮助你

大概是这样的:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/some_class/$1 [L]

注意:这与MVC结构背道而驰。

是的,您必须定义一个默认控制器,当您调用localhost时,该控制器将执行其索引功能/

但是,您也可以做您想做的另一件事,直接捕获控制器的方法,而不使用控制器名称

localhost/some_func

您需要在路由中使用通配符,

我认为您最好在codeigniter框架中使用通配符,而不是在.htaccess文件中使用通配符。在.htaccess中进行基本设置就足够了,其余的可以在应用程序中配置。这些重写规则看起来不太合理。我建议删除
RewriteCond
,只做一个
RewriteRule^$index.php/some_class[L]
,而不是引入不必要的问题。谢谢,所以你的答案的上半部分与我的情况无关,但编辑是同意的,我只是提供了一个来自谷歌搜索的快速示例。。主要是突出显示/index.php/some_class/$1特性。@Eddie,我将把这个控制器放在哪个目录中?它会被命名为index.php吗?请阅读以下内容:在继续之前学习如何创建控制器。