Can CodeIgniter route to different controllers based on port number?

376 views Asked by At

I would like to have CodeIgniter route to a different controller based on port number like so:

host_name/ControllerName      => foo() 
host_name:3000/ControllerName => bar()

I've added port 3000 to Apache's httpd.conf, so the server listens to both, but how do you tell CodeIgniter to route to a different method based on the port number? I was thinking that something like

$route[":3000/test/index"] = "ControllerName/bar"

would work, but no.

I've searched StackOverflow as well as the official documentation, but no luck.

Anyone have an idea, or is port-based routing just not supported by the framework?

1

There are 1 answers

0
shankar kumar On BEST ANSWER

use $_SERVER['SERVER_PORT'] to get port number and then write conditional routing in route.php