我在目录/system/application/controller/下有一个索引 Controller 名称 Index.php
我已经设置了 .htacesss 的规则
重写引擎开启
RewriteCond $1 !^(include||index.php|images|robots.txt)
重写规则 ^(.*)$/index.php/$1 [L]
然后我打开 $route['default_controller'] = "index";
我配置 $config['index_page'] = "";
我的 Controller 中有一个索引操作
当我访问 http://domain/index/index/en将有 404
当我访问 http://domain/index/index/index/en会没事的
我尝试在 Libraries/Router.php 中回显 $this->uri->segments
发现如果我用 index/index/en 请求,它只返回 index 和 en
如果我请求 index/index/index/en 它返回 index、index 和 en,
作为 ci 路由逻辑,第一段是 Controller 名称,第二段是 Action
能解决吗???只是不想在主页中使用太长的 url
最佳答案
documentation实际上声明 Controller 不能命名为“索引”,因为它是一个保留字。
如果您的目标是获得漂亮的 URL,您应该保留默认 Controller 的原样,并将 $config["index_page"] 变量留空。
然后创建这个 .htaccess 文件:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
那会让 CI 和你成为一对幸福的夫妇......
关于Codeigniter 索引 Controller 路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4173238/