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 291413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:05:12+00:00 2026-05-12T06:05:12+00:00

How can push a URI like this in CodeIgniter (1.7.1 currently): example.com/seg1/seg2/seg3/seg4/ or example.com/seg1/seg2/

  • 0

How can push a URI like this in CodeIgniter (1.7.1 currently):

example.com/seg1/seg2/seg3/seg4/

or

example.com/seg1/seg2/

etc. through a single class method in a controller whose name does not appear in the URI? In a regular PHP scenario I would use mod_rewrite something like this:

RewriteRule ^([^/]+)/$ myfile.php?one=$1 [L]  
RewriteRule ^([^/]+)/([^/]+)/$ myfile.php?one=$1&two=$2 [L]  
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ myfile.php?one=$1&two=$2&three=$3 [L]  
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ myfile.php?one=$1&two=$2&three=$3&four=$4 [L]

(I sanitize and validate the segments extensively in PHP, returning 404 if invalid)

But in Codeigniter I can’t figure out how to do this without hard coding at least the first segment, but then using custom routes it still wants to treat the subsequent segments as method calls.

I’m a newbie to CI, but have so far managed to port over the entire existing site with the exception of this part of it. I don’t see how all the parts come together on this problem, so any suggestion is welcome.

Clarification: I read through documentation on URI library, routing etc before starting my project, and they were helpful for various things, but this specific problem is not addressed by any of them. I’m not seeing how all segments of the URI can essentially be funneled through a controller that is not named in the URI and where all segments are arbitrary. The routing examples assume you know the value of the first segment. I already know how to remove “index.php” as well as access segments.

  • 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-12T06:05:13+00:00Added an answer on May 12, 2026 at 6:05 am

    Have you looked up URI routing in the user guide and the wiki? They should tell you almost anything about routing, rewriting and accessing the different URI segments.

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

    http://codeigniter.com/user_guide/libraries/uri.html

    http://codeigniter.com/wiki/mod_rewrite/

    [Edit:]

    Here’s the long description:
    There is no way to not “hard-code” the first segment, and you can still “hard-code” the second segment.

    What you want to accomplish can be nearly done by editing the routes in system/application/config/routes.php:

    $route['(:any)'] = 'your_default_controller/index/$1';
    
    $route['default_controller'] = "your_default_controller";
    

    So, the first segment of your URI will be the method of the controller. You can access all segments of your (initial) URI by

    $this->uri->segment(n)
    

    You would then use the method index to call the desired function for each request.

    On a side note: Why do you want to use an MVC framework for that, as you do not use much of the benefits of MVC?

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

Sidebar

Related Questions

I have a git repo on my server that I can push/pull through SSH
I'm fighting with this for days, I hope You can push me in the
I want to be able to draw an array of balls, I can push
So basically, how can I push a UIViewController from a UITableView. I have an
How can we get Push Queue Tasks scheduled for execution ASAP after enqueuing? Do
Can the .NET RIA Service automatically push data to the silverlight client without the
Can anyone confirm that after changing the Apple Push Certificate to follow the new
How can i create a chain of viewcontrollers and push them into navigation item
How can I know that my iPhone is connected to the Apple Push Notification
I can see how you can use the Acl Extension to control the push/pull

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.