Welcome Guest, Not a member yet? Register   Sign In
Index method is not loading by default on controllers
#1

Hi everyone,

I have a problem, the index method is not loading by default on any controller (instead, a 404 page is shown), I need to go to localhost/app/exampleController/index to see it.

Here my .htaccess file:
Code:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]


Thank you.
Reply
#2

Are you sure mod_rewrite is enabled?

On Linux:
Code:
sudo a2enmod rewrite
Reply
#3

Hi Diederik,

I am using xampp on Windows with 'LoadModule rewrite_module modules/mod_rewrite.so' line uncommented and 'AllowOverride All' set on all occurrences.

Here are my config and routes files if it helps:

Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$config['base_url'] = 'http://localhost/app/';
$config['index_page'] = '';
$config['uri_protocol']    = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language']    = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['cache_query_string'] = FALSE;
$config['encryption_key'] = hex2bin('RANDOM_NUMBERS_AND_CHARACTERS');
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']        = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']     = FALSE;
$config['standardize_newlines'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';

Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'pages/index';
$route['(:any)'] = 'pages/$1';

Just for clarification, I have 3 controllers, 'pages' is the main one, the other two are 'users' and 'projects'. I can access to the index method of 'pages' using 'localhost/app/' but I can't access to the index method of 'users' and 'projects' with the url 'localhost/app/users' and 'localhost/app/projects', a 404 page is shown, I need to go to '/index' to see it.
Reply
#4

Well this seems to be a routing issue: "$route['(:any)'] = 'pages/$1';" will point all requests to your pages controller. If you request localhost/users it will look for the users method inside your pages controller instead of loading the users model.

https://www.codeigniter.com/userguide3/g...uting.html
Reply
#5

The default controller does not accept a directory it should only be the controller name.

This line of code can cause problems sometimes with index method working remark it out and see if that is the case:
Code:
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB