CodeIgniter路由控制器索引函数的问题

时间:2011-02-27 11:21:49

标签: .htaccess codeigniter routing codeigniter-url

我目前的开发是使用CodeIgniter,当我尝试将一些参数传递给我的主控制器的索引函数时,它返回404 error

http://localhost/gis/1 -> 404 ERROR
http://localhost/gis/home/1 -> 404 ERROR

实际上我的route.php文件有这样的路线:

$route['default_controller'] = "home";    

$route['home/([:num])'] = 'home/index/$1';

我的.htaccess文件是这样的(从this post开始从CI网址中删除index.php):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

我的config.php文件:

$config['base_url'] = "http://localhost/gis";

$config['index_page'] = "";

我做错了什么?谢谢!

1 个答案:

答案 0 :(得分:2)

<强>更新

引用OP:

  

.htaccess无罪。问题   是我的路线需要   $ route ['home /(:num)'] = ...我添加了   括号和所有作品。


而不是:

$route['home/([:num])'] = 'home/index/$1';

尝试像这样指定:

$route['home/:num'] = 'home/index/$1';

同时确保从application/config/routes.php开始,您的默认控制器设置为home

$route['default_controller'] = 'home';