Category: Routing

Q: Cakephp 3 create sub-domain routing like

I want to create sub-domain routing for my Cakephp 3 application. The user profile url is:{username}

I would like to have sub-domain {username} pointing to ProfileController, for example:

http://{username}  =>  /profile/{username}

I have no idea how to achieve this.

1 Answers

Version: 3.0

I'm not sure if this helps CakePhp and subdomain routing.


class SubdomainRoute extends CakeRoute {

    public function match ($params) {
        $subdomain = isset($params['subdomain']) ? $params['subdomain'] : null;
        $path = parent::match($params);
        if ($subdomain) {
            $path = 'http://' . $subdomain . '.localhost' . $path;
        return $path;