Codeigniter索引控制器路由问题 [英] Codeigniter Index Controller routing problem

查看:85
本文介绍了Codeigniter索引控制器路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录/ system / application / controller /

I have a index controller name Index.php under directory /system/application/controller/

我已经设置了.htacesss的规则

and i have set the rules of .htacesss


RewriteCond $ 1上的RewriteEngine!^(include || index.php | images | robots.txt)
RewriteRule ^(。*)$ /index.php/ $ 1 [L]

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

,然后我打开$ route ['default_controller'] = index;

and i turn $route['default_controller'] = "index";

我配置$ config ['index_page'] =;

and i config $config['index_page'] = "";

并且我在控制器中有一个索引操作

and i have a index action in my controller

当我访问 http:// domain / index / index / en 时将有404

when i access http://domain/index/index/en will have 404

当我访问 http:// domain / index / index / index时/ en 会很好

,我尝试在库/Router.php中回显$ this-> uri->段

and i try to echo $this->uri->segments in Libraries/Router.php

发现如果我请求使用index / index / en,则仅返回index和en

find that if i request with index/index/en, it return only index and en

如果我请求使用index / index / index /返回索引,索引一个d en,

if i request index/index/index/en it return index, index and en,

作为ci路由逻辑,第一段是控制器名称,第二段是操作

as ci route logic the first segment is the controller name and second is the action

可以解决吧???只是不想在首页中添加太长的网址

can it be solve???? just dont want too long url in home page

推荐答案

文档实际上指出不能将控制器命名为索引,因为它是保留字。

The documentation actually states that a controller can't be named 'index' because it's a reserved word.

如果您的目标是获取漂亮的URL,则应将默认控制器保留为原来的状态,并保留$ config [ index_page]变量为空。

If you goal is to get pretty URL's you should leave the default controller as it was originally and leave the $config["index_page"] variable empty.

然后创建此.htaccess文件:

Then create this .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

这将使CI和您成为幸福的夫妻...

That would make CI and you a happy couple...

这篇关于Codeigniter索引控制器路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆