I’ve been trying to wrap my head around this concept and how to route it correct but i just have a hard time doing that.
I’m accepting all domains and subdomains to my app but here’s the issue:
Example:
john.myapp.com/foo
it should route to the foo function in the user controller instead of calling a controller called foo.
So:
john.myapp.com/foo -> myapp.com/user/foo
john.myapp.com/foo/bar -> myapp.com/user/foo/bar
someotherdomain.com/foo/bar -> myapp.com/user/foo/bar
myapp.com/foo -> the controller: foo
But this routing should only apply to subdomains and other domains, not myapp.com
Codeigniter doesn’t support routing involving domains as part of it’s default functionality.
If you visited
www.example.com/controller/methodthe router interprets only the/controller/methodpart and ignores anything before.This means to achieve what you’re trying you need to route the subdomains to the application using .htaccess.
This would send all requests like
subdomain.example.com/controller/methodgo toexample.com/index.php/user/controller/methodThis will allow you route depending on the subdomain using the standard routing functionality.