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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:53:03+00:00 2026-05-12T08:53:03+00:00

I am developing an ecommerce website with CI that has product categories and products.

  • 0

I am developing an ecommerce website with CI that has product categories and products. I want to route the URL so that it will go to the products controller, then run the getCategoryByName function for the first segment, then run the getProductByName for the second segment. Here is what I have:

URL:
products/docupen/rc805
routes.php:
$route['products/([a-z]+)'] = "products/getCategoryByName/$1";
$route['products/([a-z]+)/([a-z0-9]+)'] = "products/$1/getProductByName/$2";

But its not working. “docupen” is the category, and “rc805” is the product.

Thanks in advance.


Thank you all for your help. This is what I ended up with for what I needed.

$route['products/:any/:num'] = "products/getProductByID";
$route['products/:any/:any'] = "products/getProductByName";
$route['products/:any'] = "products/getCategoryByName";
  • 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-12T08:53:03+00:00Added an answer on May 12, 2026 at 8:53 am

    My answer builds a bit on Colin’s answer.

    When I played around with the routes in CodeIgniter I came to the conclusion that the order of the routes was important. When it finds the first valid route it won’t do the other routes in the list. If it doesn’t find any valid routes then it will handle the default route.

    My routes that I played around with for my particular project worked as follows:

    $route['default_controller'] = "main";
    $route['main/:any'] = "main";
    $route['events/:any'] = "main/events";
    $route['search/:any'] = "main/search";
    $route['events'] = "main/events";
    $route['search'] = "main/search";
    $route[':any'] = "main";
    

    If I entered “http://localhost/index.php/search/1234/4321” It would be routed to main/search and I can then use $this->uri->segment(2); to retrieve the 1234.

    In your scenario I would try (order is very important):

    $route['products/:any/:any'] = "products/getProductByName";
    $route['products/:any'] = "products/getCategoryByName";
    

    I don’t know enough to route the way you wanted (products/$1/getProductByName/$2), but I’m not sure how you would create a controller to handle this particular form of URI. Using the $this->uri->segment(n); statements as mentioned by Colin in your controller, you should be able to do what you want.

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

Sidebar

Related Questions

I am developing an eCommerce website which contains around 2000-3000 products(no.can be increase in
I'm developing an ecommerce search engine that allows you to search for products in
We're developing a new eCommerce website and are using NHibernate for the first time.
I am developing a Ecommerce website by using version Magento 1.6. I need to
I am developing an ecommerce app that is using the UPS shipping webservice. I
We're in the middle of developing a e-commerce application that will be used by
I am currently developing a ecommerce site which ofcourse contains images for each product.
I'm designing (and developing) web software that will allow the general public to sign
I am developing an e-commerce website, I want payment process to be done from
I am writing a T-SQL Query, I am developing the e-commerce website, in that

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.