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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:28:05+00:00 2026-06-11T03:28:05+00:00

It’s possible this question exists elsewhere, and if so, I apologize. After searching for

  • 0

It’s possible this question exists elsewhere, and if so, I apologize. After searching for an hour without success, I can’t help but think I’m on the wrong track.

Essentially what I am looking for is a method to enforce a description or title in a page’s URL. I am using CodeIgniter, so it is pretty simple to make a pretty URL go where ever I wish.

I could have:

http://mysite.com/controller/function/what-ever-i-want/can-go-here

and it will always go to:

http://mysite.com/controller/function/

with the variable values what-ever-i-want and can-go-here

What I would like is for the URL to be automatically rewritten to include the title if only the controller/function is given.

So, if someone went to:

http://mysite.com/controller/function/

it should automatically rewrite the url as

http://mysite.com/controller/function/a-more-descriptive-title/

A great example of the functionality that I am talking about is the SO URL. if you go to https://stackoverflow.com/questions/789439 it will automatically rewrite it to https://stackoverflow.com/questions/789439/how-can-i-parse-descriptive-text-to-a-datetime-object

I suspect that mod_rewrite is involved, but I would like to come up with the solution that works most gracefully with CodeIgniter.

I am very new to the pretty-url scene and desperately call upon the advice of someone with more experience. Thanks in advance for any help given!

  • 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-11T03:28:07+00:00Added an answer on June 11, 2026 at 3:28 am

    I used Fiddler2 to see how Stackoverflow does this.

    Part of the respnse from http://stackoverflow.com/questions/12205510/

    HTTP/1.1 301 Moved Permanently
    Location: /questions/12205510/how-can-i-enforce-a-descriptive-url-with-codeigniter
    Vary: *
    Content-Length: 0
    

    So basically when we go to controller/function/ we need to redirect user to controller/function/my-awesome-title. I’ve written simple controller that does just that:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Controller extends CI_Controller
    {
        protected $_remap_names = array();
    
        function __construct()
        {
            parent::__construct();
    
            $this->_remap_names['func'] = "My Awesome Title";
        }
    
        function _remap($method, $arguments)
        {
            if(
                isset($this->_remap_names[$method])
                && sizeof($arguments) == 0
                && method_exists($this, $method)
                )
            {
    
                $this->load->helper("url");
    
                $title = str_replace(" ", "-", $this->_remap_names[$method]);
                $title = strtolower($title);
    
                $url   = strtolower(__CLASS__)."/$method/$title";
                $url   = site_url($url);
    
                // if you dont want to have index.php in url
                $url   = preg_replace("/index\.php\//", "", $url);
    
                header("HTTP/1.1 301 Moved Permanently");
                header("Location: $url");
                header("Vary: *");
            }
            else
            {
                call_user_func_array(array($this,$method), $arguments);
            }
        }
    
        function func()
        {
            echo "<h1>";
            echo $this->_remap_names[__FUNCTION__];
            echo "</h1>";
        }
    
    };
    

    Docs for CodeIgniters _remap function can be found here in Remapping Function Calls section.

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.