路由器不工作codeigniter

时间:2018-01-18 08:13:57

标签: codeigniter routes http-status-code-404

当我将welcome设置为默认控制器时,路由不起作用,默认控制器显示错误404,然后使用欢迎控制器定义的所有路由都工作但我的其他路由和url不起作用。

$route['default_controller'] = "welcome";
$route['testRoute'] = 'welcome/test';
$route['testRoute/(:num)'] = 'welcome/test/$i';

以上所有路线仅使用欢迎控制器。

$route['default_controller'] = "login";
$route['loginMe'] = 'login/loginMe';
$route['logout'] = 'user/logout';

显示所有控制器和功能的错误404.

3 个答案:

答案 0 :(得分:0)

如果你把index.php放在域之后就行了。

http://www.example.com/index.php/login/

您应该通过替换config和.htaccess

从url中删除index.php

替换config.php

$config['index_page'] = 'index.php';

通过

$config['index_page'] = '';

的.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]

答案 1 :(得分:0)

这对我有用:

  1. 在config文件夹的config.php中,使用:$config['enable_query_strings'] = FALSE;
  2. 使用$config['uri_protocol'] = 'AUTO';
  3. Use $config['index_page'] = '';
  4. 还请记住设置您的基本URL。我的是:$config['base_url'] = 'http://localhost/code';
  5. 最后使用以下htaccess文件:

    <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /code/index.php/$1 [L] </IfModule>

注意:请记住在htaccess文件中编辑index.php的路径。希望这对您有用

答案 2 :(得分:-1)

正确配置.htaccess文件