CodeIgniter showing only default controller

后端 未结 15 2908
-上瘾入骨i
-上瘾入骨i 2021-02-14 21:59

I am using Codeigniter in Local WAMP. Here code is working fine. But i upload in Cpanel ( inside of example.com, folder name call \'mysite\'). Ther

相关标签:
15条回答
  • 2021-02-14 22:13

    There are few things that you have to take into consideration. when you setup your project with codigniter framework. following is the file that you have to make changes.

    1).htaccess:

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

    2)application/config/config.php

    $config['base_url'] = 'http://example.com/mysite/';
    $config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO';  
    

    3)application/config/database.php

    $db['default']['hostname'] = 'localhost'; // set your hostname
    $db['default']['username'] = 'root'; // set database username
    $db['default']['password'] = 'root'; //set database password
    $db['default']['database'] = 'XYZ'; //set your database name
    $db['default']['dbdriver'] = 'mysql';
    

    4)application/config/routes.php

    $route['default_controller'] = "user";  //your default controller
    $route['404_override'] = '';  
    

    Note: your .htaccess file must be in root directory. here it should be in mysite folder

    0 讨论(0)
  • 2021-02-14 22:14
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    0 讨论(0)
  • 2021-02-14 22:15
    $config['base_url'] = 'http://example.com/mysite/';
    

    Better than :

    $config['base_url'] = 'http://example.com/mysite';
    

    Try this :

    RewriteBase /
    
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
    
    0 讨论(0)
  • 2021-02-14 22:15

    CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested.So once replace your default conroller 'welcome' with your conrtoller in routes.php , it may help you

    0 讨论(0)
  • 2021-02-14 22:16

    Sometimes "ORIG_PATH_INFO" fixes this issue. So you can also try again with changing uri_protocol to "ORIG_PATH_INFO"

    $config['uri_protocol'] = "ORIG_PATH_INFO";
    

    and the base_url should be absolute,

    $config['base_url'] = "http://example.com/mysite/";
    
    0 讨论(0)
  • 2021-02-14 22:22

    Open config.php and do following replaces

    $config['index_page'] = "index.php"
    to
    $config['index_page'] = ""
    

    In some cases the default setting for uri_protocol does not work properly. Just replace $config['uri_protocol'] ="AUTO" by $config['uri_protocol'] = "REQUEST_URI"

    HTACCESS

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    
    0 讨论(0)
提交回复
热议问题