【问题标题】:Codeigniter can only display default controllerCodeigniter 只能显示默认控制器
【发布时间】:2018-10-30 19:37:47
【问题描述】:

我正在开发 codeigniter 3.1.8。它在我的本地主机上运行良好。但是,当我将它推送到 FTP 服务器时,我只能访问默认的控制器页面。当我尝试访问具有其他控制器的其他视图时,它给了我错误'404 Not Found'

配置:

$config['base_url'] = 'https://*****.net/my_project/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_hooks'] = FALSE;
$config['encryption_key'] = 'xRUqKhsoZ5qV6y3kqARFJFdPqJvp7X2z';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

路线:

$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

我已经尝试了几个.htaccess:

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

<IfModule mod_rewrite.c>

RewriteEngine On

# Set the rewritebase to your CI installation folder
RewriteBase /sandbox/ci/


# Send everything to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule> 

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 我可以发送可运行的 ci 结构吗?我认为问题出在你的结构中..
  • 我不这么认为。因为我通过创建另一个简单的控制器和视图来尝试使用 CodeIgniter 模板。它仍然存在示例问题。
  • 将此 .htaccess 文件放入系统文件夹中,如下所示 要求全部拒绝 全部拒绝

标签: codeigniter


【解决方案1】:

试试这个,它对我有用。确保该文件必须名为“Yourcontroller.php”,大写“Y”。

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

确保您已加载 uri 库 (application/config/autoload.php)

$autoload['helper'] = array('url', 'file');

在此处查看控制器命名约定:https://www.codeigniter.com/userguide3/general/controllers.html。希望这会对你有所帮助。

您好!

【讨论】:

  • 我试过了,还是不行。顺便感谢您的建议。
【解决方案2】:

这是正常问题,要修复它,您必须在文件夹中定义 .htaccess 文件。如下 这两个文件都在您的文件夹中。 将此文件放在您的主文件夹中并指定名称为 .htaccess

RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

将此文件放入您的应用程序文件夹并指定名称为 .htaccess

<IfModule authz_core_module>
  Require all denied
</IfModule>
<IfModule !authz_core_module>
  Deny from all
</IfModule>

【讨论】:

  • $config['encryption_key'] = ' ';
  • 移除 encpt 键值
  • plz 试试看它是不是醒了??
  • 不,它仍然无法正常工作。仍然给出相同的错误 404 not found
  • 检查你的主文件夹,系统文件夹和控制器.htaccess文件是否存在???
【解决方案3】:
1) first controller name and class name first character capital letter
   example :: CapturistaCtrl
2) go to config changes ::
   -> $config['index_page'] = 'index.php'; remove index.php
   -> $config['uri_protocol']   = 'REQUEST_URI'; remove (REQUEST_URI)
3) .htaccess
   <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteCond $1 !^(index\.php|resources|robots\.txt)
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
   </IfModule>

set .htaccess file 

List item

【讨论】:

  • 我已经完成了,但仍然无法正常工作。只能显示默认控制器页面
猜你喜欢
  • 2016-11-30
  • 1970-01-01
  • 1970-01-01
  • 2015-03-22
  • 1970-01-01
  • 1970-01-01
  • 2016-04-19
  • 1970-01-01
  • 2015-01-10
相关资源
最近更新 更多