usman
usman

Reputation: 55

codeigniter: How to remove only index method in URL

I am using a multiple methods in one class.I want to only remove index from url only and other remain same;

www.mysite.com/blog/index
www.mysite.com/blog/index/one/two
www.mysite.com/blog/myblog
www.mysite.com/blog/data_load/one/two

Upvotes: 2

Views: 579

Answers (4)

Sunday Okoi
Sunday Okoi

Reputation: 303

You can also use a .htaccess file to handle that. Create a .htaccess file and paste this code in it

<IfModule mod_rewrite.c>
   RewriteEngine On
   # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
   #  slashes.
   # If your page resides at
   #  http://www.example.com/mypage/test1
   # then use
   # RewriteBase /mypage/test1/
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule>

Upvotes: 0

louk
louk

Reputation: 97

Try this in application/config/routes.php:

$route['blog/myblog']                   = 'blog/myblog';
$route['blog/data_load/(.+)/(.+)']      = 'blog/data_load/$1/$2';
$route['blog']                          = 'blog/index';
$route['blog/(.+)']                     = 'blog/index/$1';
$route['blog/(.+)/(.+)']                = 'blog/index/$1/$2';

Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.

Upvotes: 2

Pradeep
Pradeep

Reputation: 9717

Hope this will help you :

in route.php

$route['blog'] = 'blog/index';

Make sure :

in your config file set this :

 $config['base_url'] = 'http://localhost/foldername/';

 $config['index_page'] = '';

Upvotes: 3

NigSys Technologies
NigSys Technologies

Reputation: 141

you need to set route for that.

set route in your application/config/routes.php file

$route['project/user/id/(:any)'] = 'project/user/index/id/$1';

Upvotes: 0

Related Questions