How to remove Controller and function name from UR

2020-02-11 07:46发布

I am having a serious issue with one application developed in CI. Currently my URLs look like this

http://www.example.com/content/index/mission/

I want to remove /content/index/ from URL So, It should look something like this.

http://www.example.com/mission

I have routing and .htaccess method as well. But nothing seems to be working.

Here is my .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|css/js/style/system/feature_tab/robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

I have also tried routing of CI by defining reouters in config/router.php But it was not working :(

2条回答
\"骚年 ilove
2楼-- · 2020-02-11 08:00

For your specific example, you'll want to create a route (in application/config/routes.php) that maps

$route['mission/']

to

"content/index/mission"

In other words, $route['mission/'] = "content/index/mission";

See the CI documentation regarding URI routing for more info

查看更多
老娘就宠你
3楼-- · 2020-02-11 08:08

You can go into application/config/routes.php and set your own URL routing rules. (i.e. use something totally different than Controller/Funcction). There should be an array called $route which lets you assign mappings of url => controller/function. Hope this helps.

Check out this guide, its right up you're alley:

http://codeigniter.com/user_guide/general/routing.html

查看更多
登录 后发表回答