Search code examples
php.htaccesscodeignitercodeigniter-routing

Codeigniter, bypassing the main or default controller


i tried to find solution, but i think i am quite doing something wrong here,

i hope any one with good knowledge of codeigniter routing can help me in this regard.

what i want is that,

i have default controller named main

$route['default_controller'] = "main";
$route['404_override'] = '';

my site urls are like

mydomain.com/main/#home
mydomain.com/main/#search
mydomain.com/main/#login

what i want is to remove/hide the main from center and links can directly work. like this

mydomain.com/#home

however i did succeeded a little using codeigniter documentation. This is what i did to achieve it. in route file i added this

$route['(:any)'] = "main/$1";

it worked but it messed up with other links.

First now domain.com/main/#home stopped working. second, now i cant have other controller name here??

i mean if i try this domain.com/virtualvault/#search, it wont work..

What i am trying to have that, When i go to domain.com/main/#home it should go to home page and also when i try domain.com/#home it should also go to same home page not to forget that i want other controllers to be working fully. i mean, domain.com/othercontrollername/#function should work.

what and how to achieve it, .htaccess or route php file..

i even tried this below route code.

$route['#+(:any)'] = "main/#+$1";

but i am no good in this routing or .htaccess files.

any ideas how to achieve it??


Solution

  • // The below line is for the old controller to work as before
    $route['main/(:any)'] = "main/$1"; 
    
    //This line is for making other controllers work as before, you have to put them all
    $route['virtualvault/(:any)'] = "virtualvault/$1";
    
    //This is the last line; the order is important
    $route['(:any)'] = "main/$1";