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

  • SEARCH
  • Home
  • 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 6627037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:57:56+00:00 2026-05-25T21:57:56+00:00

I have a problem with Codeigniter routes. I would like to all registered users

  • 0

I have a problem with Codeigniter routes. I would like to all registered users on my site gets its own “directory”, for example: www.example.com/username1, www.example.com/username2. This “directory” should map to the controller “polica”, method “ogled”, parameter “username1”.

If I do like this, then each controller is mapped to this route: “polica/ogled/parameter”. It’s not OK:

$route["(:any)"] = "polica/ogled/$1";

This works, but I have always manually entered info in routes.php:

$route["username1"] = "polica/ogled/username1";

How do I do so that this will be automated?

UPDATE:
For example, I have controller with name ads. For example, if you go to www.example.com/ads/
there will be listed ads. If you are go to www.example.com/username1 there are listed ads by user username1. There is also controller user, profile, latest,…

My Current routes.php:

$route['oglasi'] = 'oglasi';
$route['(:any)'] = "polica/ogled/$1"
$route['default_controller'] = 'domov';
$route['404_override'] = '';

I solved problem with this code:

$route['oglasi/(:any)'] = 'oglasi/$1';
$route['(:any)'] = "polica/ogled/$1"
$route['default_controller'] = 'domov';
$route['404_override'] = '';

Regards, Mario

  • 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-25T21:57:56+00:00Added an answer on May 25, 2026 at 9:57 pm

    The problem with your route is that by using :any you match, actually…ANY route, so you’re pretty much stuck there.
    I think you might have two solutions:

    1)You can selectively re-route all your sites controller individually, like:

    $route['aboutus'] = "aboutus";
    $route['where-we-are'] = "whereweare";
    //And do this for all your site's controllers
    //Finally:
    $route['(:any)'] = "polica/ogled/$1";
    

    All these routes must come BEFORE the ANY, since they are read in the order they are presented, and if you place the :any at the beginning it will happily skip all the rest.

    EDIT after comment:

    What I mean is, if you’re going to match against ANY segment, this means that you cannot use any controller at all (which is, by default, the first URI segment), since the router will always re-route you using your defined law.
    In order to allow CI to execute other controllers (whatever they are, I just used some common web pages, but can be literally everything), you need to allow them by excluding them from the re-routing. And you can achieve this by placing them before your ANY rule, so that everytime CI passed through your routing rules it parses first the one you “escaped”, and ONLY if they don’t match anything it found on the URL, it passes on to the :ANY rule.

    I know that this is a code verbosity nonetheless, but they’ll surely be less than 6K as you said.
    Since I don’t know the actual structure of your URLs and of your web application, it’s the only solution that comes to my mind. If you provide further information, such as how are shaped the regular urls of your app, then I can update my answer

    /end edit

    This is not much a pratical solution, because it will require a lot of code, but if you want a design like that it’s the only way that comes to my mind.
    Also, consider you can use regexes as the $route index, but I don’t think it can work here, as your usernames are unlikely matchable in this fashion, but I just wanted to point out the possibility.

    OR

    2) You can change your design pattern slightly, and assign another route to usernames, something along the line of

    $route['user/(:any)'] = "polica/ogled/$1";
    

    This will generate quite pretty (and semantic) URLs nonetheless, and will avoid all the hassle of escaping the other routes.

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

Sidebar

Related Questions

I have a weird problem. I am making kinda my own framework like codeigniter
I have a site using CodeIgniter that is almost complete now. My problem is
I have a problem making a url in Codeigniter. The url is mywebsite.com/users/mike where
I have problem with return statment >.< I want to store all magazine names
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
i have problem with autorotate on iphone i set up in all classes -
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a strange problem with codeigniter upload class. I use uploadify (http://www.uploadify.com) to
I have got a problem with my codeigniter library. To transform database data into
How can push a URI like this in CodeIgniter (1.7.1 currently): example.com/seg1/seg2/seg3/seg4/ or example.com/seg1/seg2/

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.