开发者

How to remove Controller and function name from URL in CodeIgniter

开发者 https://www.devze.com 2023-04-10 03:09 出处:网络
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 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\.ph开发者_开发技巧p|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 :(


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


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

0

精彩评论

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

关注公众号