KarSho
KarSho

Reputation: 5746

CodeIgniter showing only default controller

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'). There I changed as,

And also changed .htaccess(mysite/.htaccess) as,

<IfModule mod_rewrite.c>

RewriteEngine On

# Set the rewritebase to your CI installation folder
RewriteBase /mysite/


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

But not in mysite/application/.htaccess . It's empty.

Problem is, If I go http://example.com/mysite , it's showing default page as correctly. But if I click any link (http://example.com/mysite/user/signin), it's showing same default page. but URL is changed.

help me, Please...

config.php

$config['base_url'] = 'http://example.com/mysite';
$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['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_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '';
$config['encryption_key'] = '***';
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = 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['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
define('CSS_FOLDER' , 'application/assets/css');
define('DEFAULT_IMAGE_URL' , 'application/assets/images/default');

routes.php

$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['user/(:any)'] = 'user/index';

Upvotes: 10

Views: 19232

Answers (15)

thinhnk
thinhnk

Reputation: 361

try this

$config['uri_protocol'] = 'PATH_INFO';
$config['enable_query_strings'] = FALSE;

Httaccess

<IfModule mod_rewrite.c>
RewriteEngine On

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC]
</IfModule>

Upvotes: 0

Questioner
Questioner

Reputation: 21

I solved the same issue by changing the controller file name to start with a capital letter.

Just like the default 'Welcome' controller downloaded.

Upvotes: 1

Dhaval Bharadva
Dhaval Bharadva

Reputation: 3083

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

Upvotes: 0

Sumit
Sumit

Reputation: 708

Don't write anything in .htaccess file and remove $route['user/(:any)'] = 'user/index'; line and one thing very important make sure in your server mod rewrite extension should me enabled.

may this help you How to enable mod_rewrite in php.ini on shared hosting

Upvotes: 1

Balaji Kandasamy
Balaji Kandasamy

Reputation: 4506

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/";

Upvotes: 1

nana.chorage
nana.chorage

Reputation: 506

i was facing same issue ..its resolved when i use

$config['uri_protocol'] = 'AUTO'; 

in config.php ..try using AUTO and PATH_INFO for the same

make sure rewrite_module is on in apache

Upvotes: 4

Xavier W.
Xavier W.

Reputation: 1360

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

Upvotes: 7

Rahul Tailwal
Rahul Tailwal

Reputation: 3213

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] 

Upvotes: 1

Kong Jin Jie
Kong Jin Jie

Reputation: 535

Remove

$route['user/(:any)'] = 'user/index';

in your routes.php file. user/signin matches the above condition, that is why CI route the request to user/index instead of your "User" controller "signin" function.

What are you trying to achieve with that route configuration?

Upvotes: 1

Janith Chinthana
Janith Chinthana

Reputation: 3844

I used following .htaccess file and it works for me with cpanel.

# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php

# Rewrite engine
RewriteEngine On

# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

Upvotes: 1

DeiForm
DeiForm

Reputation: 664

Try this htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

Also you should have created controller named user and this controller should ahve function signin.

Upvotes: 1

Miomir Dancevic
Miomir Dancevic

Reputation: 6852

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Upvotes: 1

Manju
Manju

Reputation: 765

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

Upvotes: 1

Rajesh R
Rajesh R

Reputation: 125

.htaccess Code

Restore the default config to config.php, Hope this helps you.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Upvotes: 3

furas
furas

Reputation: 142631

If you plan to use subfolder on server do the same on local WAMP. This way you can test it before you send it on server.

I was using CI long time ago but I think you have to add mysite/ in some config file.

See: Installing a CodeIgniter application in a subfolder

Upvotes: 1

Related Questions