Reputation: 11445
I want to redirect home controller to my domain, it should look like this
http://sample.com/home to http://sample.com
http://sample.com/home/index to http://sample.com
http://localhost:8888/sample/home to http://localhost:8888/sample/
http://localhost:8888/sample/home/index to http://localhost:8888/sample/
is it possible? And how to do it?
Upvotes: 0
Views: 485
Reputation:
When you need to redirect to home page redirect('/');
On your config base_url() make sure is set
$config['base_url'] = 'http://sample.com/';
You may need to remove index.php and have a suitable htaccess file in main directory.
$config['index_page'] = '';
Htaccess example for main directory
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Your home controller route should the be set on default route application -> config -> routes.php
Codeigniter URI Routing User Guide Page
$route['default_controller'] = 'home';
Then autoload url helper
$autoload['helper'] = array('url');
The if you need to redirect to home controller make sure file name Home.php
and use redirect('/');
Note: Codeigniter 3 is case sensitive make sure first letter all ways upper case on file name and class name
Upvotes: 1