ReNiSh AR
ReNiSh AR

Reputation: 2852

Routing issues with custom route in Codeigniter

My controller structure (api is the folder inside controller)

controllers/api/Api_1_0.php
controllers/api/Api_2_0.php

In my routes.php

$route['api/(\d+)\.(\d+)']          = "api/Api_$1_$2";
$route['api/(\d+)\.(\d+)/(:any)']   = "api/Api_$1_$2/$3";

The routing strategy i need is, if /api/2.0 is specified it will point to controller file Api_2_0.php

ie. api/x.y points to file Api_x_y.php

Everything working fine with above routing but below is my issue:

https://www.example.com/api/2.0/photos/1234567890 // not working

https://www.example.com/api/2.0/photos // working

How to solve ?

Upvotes: 0

Views: 106

Answers (1)

user3336208
user3336208

Reputation: 148

As mentioned in a comment you should change the order.

But you should also change (:any) to (.*). (:any) would only match first segment of your url.

So correct way would be:

$route['api/(\d+)\.(\d+)/(.*)']   = "api/api_$1_$2/$3";
$route['api/(\d+)\.(\d+)']        = "api/api_$1_$2";

Upvotes: 1

Related Questions