开发者

Hiding default controller name in PHP CodeIgniter URLs

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 convention开发者_开发百科al 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?


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.


Have you tried using

$route['default_controller'] = 'con_index'

CodeIgniter Default Controller


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜