daulat daulat - 1 year ago 71
PHP Question

unlimited parameters get last one

I'm using codeigniter. How can I get last part of my URL like:


Parameters may be unlimited or there may be only one. Inside of my Controller Home and method Index, I just want last part of url e.g "subcategory"

  1. if url is www.example.com/uk-en/category I want "category"

  2. if url is www.example.com/uk-en I want "uk-en"


if url is www.example.com/Home/index/uk-en/category then it's working

but What i want without class name "Home" and method "index"

Like this www.example.com/uk-en/category

defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller{
public function index($params=[]){
echo $last;


defined('BASEPATH') OR exit('No direct script access allowed');
$route['(:any)'] = 'Home/index';
$route['default_controller'] = 'Home';
$route['404_override'] = 'error_404/index';
$route['translate_uri_dashes'] = FALSE;


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Answer Source

Use this in your routs

$route['(.*)'] = "Home/index";

This to print all routs in your controller in your index function

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download