1
votes

I'm facing an issue with codeigniter URI routing.

I have a route like this:

website.local/terms/SOMEINFORMATIONID/SOMECURRENCY

Where SOMEINFORMATIONID & SOMECURRENCY are the URI parameters.

The problem is, when I call website.local/terms/SOMEINFORMATIONID/SOMECURRENCY/SDFSDFSDFSD

So this means, that i'm introducing a third parameter, the URI still works, but what I want is, when the route is "executed" with more than 2 parameters, get a 404 error.

I was trying to find something in codeigniter documentation, but I couldn't find anything, anyway I don't know for what I should look for (codeigniter uri parameters limited, etc...).

As additional information, my route looks like this in routes.php:

$route['terms/(:any)/(:any)'] = 'xxx/terms/$1/$2';
2
hi, if you are using ci3, you can add one more route at last like $ route ['(. +)'] = 'error_page'; // all the url´s that you don't have before will display the error you want - elddenmedio
okay that's algo a good solution, I think it's more accurate for what I wanted, but I can't mark a comment as a valid answer :( so if you post an answer to the post, i'll mark it as "accepted answer" - DaRo

2 Answers

3
votes

in controller: //check segment

$sdf= $this->uri->segment(4);
if ( ! empty($sdf)) $this->my404();

and function

public function my404 () {

    $this->output->set_status_header('404');
    $data['error'] = 'Not Found...'
    $this->smarty->view( 'error.tpl', $data);
 }
0
votes

if you are using ci3, you can add one more route at last like

$ route ['(. +)'] = 'error_page'; // all the url´s that you don't have before will display the error you want