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;

Created: 28 Sep '16

Last Reply: 4 Oct '16

Replies: 1

Views: 4771

Votes: 0

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.

Join Now Tour

Download Cakephp

Start baking your own CakePHP application!

Cakephp All Versions