Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used Fiddler2 to see how Stackoverflow does this.</p> <p>Part of the respnse from <code>http://stackoverflow.com/questions/12205510/</code></p> <pre><code>HTTP/1.1 301 Moved Permanently Location: /questions/12205510/how-can-i-enforce-a-descriptive-url-with-codeigniter Vary: * Content-Length: 0 </code></pre> <p>So basically when we go to <code>controller/function/</code> we need to redirect user to <code>controller/function/my-awesome-title</code>. I've written simple controller that does just that:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Controller extends CI_Controller { protected $_remap_names = array(); function __construct() { parent::__construct(); $this-&gt;_remap_names['func'] = "My Awesome Title"; } function _remap($method, $arguments) { if( isset($this-&gt;_remap_names[$method]) &amp;&amp; sizeof($arguments) == 0 &amp;&amp; method_exists($this, $method) ) { $this-&gt;load-&gt;helper("url"); $title = str_replace(" ", "-", $this-&gt;_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 "&lt;h1&gt;"; echo $this-&gt;_remap_names[__FUNCTION__]; echo "&lt;/h1&gt;"; } }; </code></pre> <p>Docs for CodeIgniters <code>_remap</code> function can be found <a href="http://codeigniter.com/user_guide/general/controllers.html" rel="nofollow">here</a> in Remapping Function Calls section.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload