Search code examples
.htaccesscodeigniterhttp-redirecturl-routing

codeigniter -URL Redirect with out controller in url


I will explain my question with an example

http://localhost/tutorial/tut/main_module/sub_title

say my controller name is tut and main_module and sub_title is two dynamic text only. My requirement is based on this sub_title i have to load content.

How i can hide controller name. expected final url will be http://localhost/tutorial/main_module/sub_title


Solution

  • You can use route rules for this. This should work for your exact example:

    $route['main_module/sub_title'] = 'tut/main_module';
    

    So for dynamic routes:

    $route['(:any)/(:any)'] = 'tut/$1/$2';
    

    Please note that this means any other route in your project will not work, as this is essentially a 'catch all' route. You will need to explicitly list all other routes with just two parameters

    See the docs