路线不工作codeigniter

问题描述 投票:0回答:3

当我将welcome设置为默认控制器时,路由不起作用并且默认控制器显示错误404,然后使用welcome控制器定义的所有路由都起作用,但我的其他路由和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。

codeigniter routes http-status-code-404
3个回答
11
投票

如果你把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
投票

这对我有用:

  1. 在config文件夹的config.php中,使用:
    $config['enable_query_strings'] = FALSE;
  2. 使用
    $config['uri_protocol'] = 'AUTO';
  3. Use $config['index_page'] = '';
  4. 还记得设置您的基本网址。我的是:
    $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 的路径。希望这对你有用


0
投票

在主目录中创建“.htaccess”文件,其中包含以下代码。有关更多信息,请参阅 Codeigniter 3 URL 用户指南。 .htaccess file path

更多信息:https://codeigniter.com/userguide3/general/urls.html#removing-the-index-php-file

.htaccess 文件内容: 重写引擎开启 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php/$1[L]

© www.soinside.com 2019 - 2024. All rights reserved.