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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:06:33+00:00 2026-06-05T16:06:33+00:00

I have some questions concering routing with Codeigniter. What I´m doing now is the

  • 0

I have some questions concering routing with Codeigniter. What I´m doing now is the following:

$route['articles/(:num)'] = 'articles/view/$1'; // $1 will contain an ID

This means that example.com/articles/123 will work perfectly and load an article with an ID of 123. But I also want to have the possiblilty to add the aticle´s title to the URL (for SEO). Example: example.com/articles/123/article-title

What I want is pretty much the same thing as Stack Overflow: stackoverflow.com/questions/123/the-title

How can I do that?

I´m also wondering how Stack Overflow works. If I go to stackoverflow/questions/111 the title will automatically be added to the url. Is that done with php redirect()?

  • 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-06-05T16:06:34+00:00Added an answer on June 5, 2026 at 4:06 pm

    I have done something similar in the past; I can’t find it know but IIRC (it was months ago) You can use a route like you did, and also add a more specific one, like

    $route['articles/(:num)/(:any)'] = 'articles/view/$1/$2';
    $route['articles/(:num)'] = 'articles/view/$1';
    

    As you can see, both map to the same method, which is kind of “overloaded”; you can make up for a missing parameter by using a default value:

    function articles($id,$slug = FALSE) 
    { }
    

    and simply ignore the second parameter in your article retrieval.

    As for adding the title you can:

    1. have a “slug” field in your database, created when the article is saved. You can use the comfortable url_title($title,'dash',TRUE) function (in the url helper), which takes the $title, uses the dash as separator, and make it all lowercase;
    2. use the above function and convert the title of the article (after you retrieved it from the database) “on-the-fly”; just check on the article() method if the 2nd parameter isn’t false and you’ll know if you need to create the slug or not;

    As for how to show the slug even when using an url without it you can make, as you guessed, a redirect, but since both routes point to the same method it won’t change anything for you.

    Oh, uhm, beware of loops while calling the redirect, check carefully 😉

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

Sidebar

Related Questions

i have some questions about constructors in ColdFusion : must i use the name
I have some questions about using MySQLi queries, and related memory management. Suppose I
I have some questions about the default values in a function parameter list Is
I have some questions which are as follows: How can I use the JSP
I have some questions about vector in STL to clarify..... Where are the objects
I have some questions about the registry. We have Preferences p = Preferences.userRoot(); If
I have some questions about the performance of this simple python script: import sys,
I actually have some questions (real childish). 1) If I know that a website
I am using Tomcat 6 and have some questions about Apache mod_jk as follows.
I've read some documentation on how Adaboost works but have some questions regarding it.

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.