Routing with floats in the URL


#1

Hi guys, sorry if this is a silly question but any idea why, given a routing rule of:

$app->get(’/calculator/{operator}/{parameter1}/{parameter2}’, CalculatorHandler::class . ‘:calculate’);

/calculator/1/5/5

works, but

/calculator/1/5/5.5

does not?

I’ve tried adding a regular expression to the parameter2 routing rule, but no luck there either.

Thanks in advance.


Path issue (404) on some routes using PHP builtin webserver
#2

Are you using the PHP built-in web server? It may actually try to look for a file called 5.5 instead of calling the Slim front controller.


#3

Thanks for your reply. Yes I am. Is there anything that can be done to make the route work? If not, I’ll just switch to posting the parameters instead.


#4

You can use index.php/calculator/1/5/5.5 instead of calculator/1/5/5.5 in the URL to ensure that the PHP built-in web server calls the front controller (index.php).

Another option is to use a router script when starting the built-in web server, see for example https://gonzalo123.com/2012/10/15/how-to-rewrite-urls-with-php-5-4s-built-in-web-server/.


#5

Much appreciated, thank you!