Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:28:08+00:00 2026-05-26T05:28:08+00:00

I have a controller for example: class Users extends CI_Controller { function index() {

  • 0

I have a controller for example:

class Users extends CI_Controller
{
    function index()
    {
        $this->load->library('pagination');

        $config['base_url'] = base_url() . 'index.php/users';
        $config['total_rows'] = 55;
        $config['per_page'] = 10;
        $this->pagination->initialize($config); 

        echo $this->pagination->create_links();
    }
}

Then the pagination will be:

base_url() . 'index.php/users/10
base_url() . 'index.php/users/20
base_url() . 'index.php/users/30
..

THE PROBLEM

It displays the links fine, but when I click it shows 404.
It works fine only if the links will be like this (with the function index):

base_url() . 'index.php/users/index/10
base_url() . 'index.php/users/index/20
base_url() . 'index.php/users/index/30
..

Anyway, I don’t want that the users will see the address with index, what should I do?
I want to cancel the address with index + the pagination will work without it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:28:08+00:00Added an answer on May 26, 2026 at 5:28 am

    The index has to be there otherwise codeigniter won’t know which function to call (the “index()” function in your controller).

    Your best bet is to use URI routing.

    Add something like this (untested):

    $route['users/page/:num'] = "users/index";
    

    Into the file “application/config/routes.php”

    However the pagination library may still add the index in which case you would need to extend it or create your own. However using the following base url may work:

    class Users extends CI_Controller
    {
        function index()
        {
            $this->load->library('pagination');
    
            $config['base_url'] = base_url() . 'index.php/users/page/';
            $config['total_rows'] = 55;
            $config['per_page'] = 10;
            $this->pagination->initialize($config); 
    
            echo $this->pagination->create_links();
        }
    }
    

    Again that is untested. Sorry for the untested examples, but you will definitely need uri routing to do what you need, there is further information about uri routing here

    In order to deal with any SEO issues with the old uri working you can try any of the following.

    To redirect every time a user hits the uri format that you don’t want to appear you can redirect to them to the correct version by putting this at the top of your index() function in the users controller.

    $this->load->helper('url');
    $current_uri = uri_string();
    if(strpos($current_uri, 'users/index'))
    {
        $new_uri = str_replace('users/index','users',$current_uri);
        redirect($new_uri);
    }
    

    Alternatively you can set a canonical meta tag in the HTML, this tells search engine spiders that although the page it’s looking it at should be treated as the page in the canonical tag, not the address bar. Find more on the canonical tag here

    <link rel="canonical" href="<?php echo site_url('users/'.$page_num); ?>" />
    

    Of course you will have to adjust the variables as necessary above.

    You could also do it via htaccess but without the means to test it just at the moment i’m weary of trying to give any examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: I have a view controller and get rid of it. But there's still
Let's have an example. In application I have a tab bar controller. Tab bar
I'd like to have URLs that are even shorter than /{Controller}/{Action}/{Id}. For example, I'd
I have a controller with an action method as follows: public class InventoryController :
I have 2 projects - a class library containing an EDM Entity Framework model
I have seen example code that looks like this, which seems perfectly reasonable: [Authorize(Roles
I have controller with action new , and I want it to create ActiveRecord::Base
When submitting one form from view, how can i also read or have controller
I have a controller action that is being executed by a link that was
I have a controller action which I would like to call another controller action.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.