My url like this
"mydomain.com/index.php/user/rbkdon3"
I want to make like a facebook as:
mydomain.com/rbkdon3
Note:Username is the combination of alphabets+numbers.
What should i need to be done in routes.php file to achieve my requirement.
My url like this
"mydomain.com/index.php/user/rbkdon3"
I want to make like a facebook as:
mydomain.com/rbkdon3
Note:Username is the combination of alphabets+numbers.
What should i need to be done in routes.php file to achieve my requirement.
you must use apache rewrite module and use .htaccess first
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
and delete index.php from applications/config/config.php
$config['index_page'] = "index.php";
and route with
$route['(^(?=[^\s]*?[0-9])(?=[^\s]*?[a-zA-Z])[a-zA-Z0-9]*$)'] = "user/$1";`
regex is updated
By this way you can achieve it.
$route['(:any)'] = 'user/'.$username;
Creating this route dynamically is bit complex
We have to create this route only if user exits in the database, so it will not affect other controllers. Write below code in your routes.php
$username = explode('/', $_SERVER['REQUEST_URI']);
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->where('username', $username[1] ); //check user name 
$query = $db->get( 'tbl_users' ); //table name in which user exits
if($query->num_rows > 0){ //if exits the create routing
    $route['(:any)'] = 'user/'.$username[1]; // here you can define any controller and function name as required for the demo I have given this "'user/'.$username[1]"
}
Note: Remove index.php from url using .htaccess file.