2
votes

I am trying to remove the default controller name from URLs in CodeIgniter using htaccess; I have hidden index.php but also want rid of the default controller which is currently called con_index.

For example if site root was mysite.com, mysite.com/con_index/function1 would change to mysite.com/function1 and so on.

All other controllers can remain in the url, so if I had another controller called locations with a function called location1, mysite.com/locations/location1 would stay the same.

I think this makes for a more conventional structure rather than a class and function name popping in there the second you leave the site root. Gnashed my teeth trying to achieve this, can anyone help?

3
Can't you just create a controller called "function1" and leave the "con_index" controller only for your home page? - Nick Pyett

3 Answers

1
votes

Try this inside your .htaccess :

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.*)\/$ index.php/com_index/$1 [nc] [L]

This would replace any occurrences inside brackets with $1. So, when you're calling www.example.com/function_1/ it actually calls www.example.com/com_index/function_1

However, I'm not sure it works for CI because CI might have some restrictions for accessing the URL Route.

0
votes

Have you tried using

$route['default_controller'] = 'con_index'

CodeIgniter Default Controller

0
votes

enter code here$route['(:any)'] = 'controller_name/function_name/$1';

it will replace controller and then u can try to access url by not putting controller name in it.