Search code examples
phpcodeigniterurlslash

php URL segment goes unexpected to index


This is weird... I'm using the MVC pattern in php (codeigniter) to display a user's created categories. The URL pointing to a user's categories is

http://mysite.com/categories/user

This works in the Google Chrome browser but if Firefox it takes me to the index. Adding a trailing slash...

http://mysite.com/categories/user/

...takes me to the correct destination in both browsers. Also renaming the user controller works.

Inside controller

function user()
{
        $data['query'] = $this->Category_model->read_all_user_categories();
        $this->load->view('categories/read/user_categories', $data);    
}

The Model just returns a query.

What typically causes this behavior? I looked in all my files and can't find the culprit.

Crossing out possible causes:

  • I don't have identical functions named user
  • No Controller named user
  • No library, helper named user

What could it be?


Solution

  • I just checked CI's docs, and:

    The "index" function is always loaded by default if the second segment of the URI is empty.

    Sorry for the mistaken information.

    The sentence below is still valid (confirmation: http://wordpress.org/support/topic/links-to-wordpress-post-tabs-pages-must-have-trailing-slash)

    The reason that it works on Chrome but not on Firefox, is due to Chrome's behavior of removing the last slash when submitting the request.