title: Custom Profile URL like <site url>/<username> Codeigniter
body: <p>I want to get the user's profile by <strong>www.siteurl.com/user/username instead of www.siteurl.com/user?name=username</strong></p>
  
  <p>This is perfectly working in localhost, but not in <strong>live server
  It just give a 404 Page Not Found, But in localhost it directs to requested url</strong>. How can I do this in live server?</p>
  
  <p>This is my code</p>
  
  <p>In <code>config.php</code> enabled the hooks</p>
  
  <pre><code>$config['enable_hooks'] = TRUE; 
  </code></pre>
  
  <p>Then create a hooks.php adding following code in application->config </p>
  
  <pre><code>$hook=array(
          'pre_system' =&gt; array(
                  array(
                          'class'    =&gt; 'Userlookup',
                          'function' =&gt; 'check_uri',
                          'filename' =&gt; 'Userlookup.php',
                          'filepath' =&gt; 'hooks',
                          'params'   =&gt; NULL,
                  ),
          ),
  );
  </code></pre>
  
  <p>Then, in application-> hooks create Userlookup.php it contains,</p>
  
  <pre><code>&lt;?php defined('BASEPATH') or die('No direct script access allowed');
  
  class Userlookup{
  
      protected $uri_username;
      protected $connection_method;
  
      protected $hostname;
      protected $username;
      protected $password;
      protected $database;
  
      public function __construct()
      {
          // Configure database connection
          include(APPPATH.'config/database'.EXT);
          $this-&gt;hostname = $db[$active_group]['hostname'];
          $this-&gt;username = $db[$active_group]['username'];
          $this-&gt;password = $db[$active_group]['password'];
          $this-&gt;database = $db[$active_group]['database'];
  
     }
  
      public function check_uri()
      {
           // First, we need get the uri segment to inspect
           $request_uri = explode('/',substr($_SERVER['REQUEST_URI'], 1));    //$request_uri[0] == username
           $this-&gt;uri_username = array_shift($request_uri);                   //string 'socialsite' (length=10)
           $connection_router = array_shift($request_uri);
           $this-&gt;connection_method = empty($connection_router) ? 'index' : $connection_router;
           // Connect to database, and check the user table
           mysql_connect($this-&gt;hostname, $this-&gt;username, $this-&gt;password) AND mysql_select_db($this-&gt;database);
           $res = mysql_query("SELECT user_Id FROM tbl_user WHERE user_name='".$request_uri[0]."'");
          // $id = mysql_result("SELECT user_Id FROM tbl_user WHERE user_name='".$request_uri[0]."'");
          // var_dump($id,0);die;
  
          // print_r($id);die;
  
           if ($row = mysql_fetch_object($res))
           {
                  // If, there is a result, then we should modify server data
                  // Below line means, we told CodeIgniter to load
                  // 'User' controller on 'index', 'info' or any valid connection/method and we send 'id' parameter
                  //$_SERVER['REQUEST_URI'] = '/user';
              $id = mysql_result($res,0);
                  //print_r($id);die;
                  $_SERVER['REQUEST_URI'] = '/user?id='.$id;
                  //var_dump($_SERVER['REQUEST_URI']);die;
  
           }
           mysql_free_result($res);
      }
  
  } 
  </code></pre>
  
  <p>This is my .htaccess file</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteRule ^(.*)$ /index.php/$1 [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
  </code></pre>