Please help I want to use first URI segment into my CodeIgniter website.
Like when I open these url they opens my profile: http://www.facebook.com/buddyforever or
You can do this using the URL routing of codeigniter...
If you want your URL to be http://www.mydomain.com/zarpio
and you want it to refer to your_controller
, then do the following.
/config/routes.php
$route['(.*)'] = "your_controller/$1"; // Now, `zarpio` will be passed to `your_controller`
You can access it in your controller like this...
$my_name = $this->uri->rsegment(2);
However I do not suggest this way of configuring URLs. A better way would be...
$route['users/(.*)'] = "your_controller/$1";
This way, you're just renaming your controller name your_controller
to users
.
If you want to access profile of a user, you can do it like this...
$route['users/profile/(.*)'] = "another_controller/method/$1";
$route['users/(.*)'] = "your_controller/$1";
Consider the order of routing. Since you wrote users/(.*)
in your route, it will match users/zarpio
as well as users/profile/zarpio
, and route both of them to your_controller/$1
, which in the case of profile will give you a 404 page not found
error. That is why you need to write users/profile/(.*)
before users/(.*)
in your routing configuration.
More information in codeigniter URI class documentation