How can I rewrite the following urls in CodeIgniter
localhost/users/show_profile/john
to
localhost/john
Thanks
How can I rewrite the following urls in CodeIgniter
localhost/users/show_profile/john
to
localhost/john
Thanks
you can achieve dynamic URL using CodeIgniter Routes.
Assuming
localhost/users/show_profile/john
We're looking at:
localhost/controller/method/variable
we can use the following route:
$route['([a-zA-z_]+)'] = "users/show_profile/$1";
You can access the variable by calling $this->uri->segment(1);
inside show_profile() function.
IMPORTANT: keep the $route['([a-zA-z_]+)']
at the end of the routes.php file, to make sure it's not overriding any other routes.
If you only need to do it for a defined set of URLs, update /config/routes.php
If you need it to be dynamic then you should extend the CodeIgniter Router Library.
http://codeigniter.com/user_guide/general/creating_libraries.html (look for Extending Native Libraries)
In config/routes.php
add $route['(:any)'] = "users/show_profile/$1";
More info on routes here