Codeigniter只能显示默认控制器

时间:2018-05-21 07:25:46

标签: codeigniter

我正在研究codeigniter 3.1.8。它在我的localhost上工作正常。但是,当我将其推送到FTP服务器时,我只能访问默认控制器页面。当我尝试访问其他具有其他控制器的视图时,它会给出错误' 404 Not Found'

config:

$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> 

任何帮助将非常感谢。谢谢!

3 个答案:

答案 0 :(得分:0)

试试这个,它对我有用。确保该文件必须被称为'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。希望这会对你有所帮助。

问候!

答案 1 :(得分:0)

  

这是正常的问题,为了修复它你必须在你的文件夹中定义.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>

答案 2 :(得分:0)

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