How to create subdomain using username (3.3.15)

  1. How to create a subdomain for each user. Users have the unique username. Like wordpress

  2. How to direct username.domain.com to a user profile.

In my opinion

  1. sub.domain.com to root // .httaccess

  2. get subdomain and redirect to domain.com/users/username // cakephp

    $subdomain = $request->subdomains(1);
    $routes->connect(
    ’/’.$subdomain,
    [‘controller’ => ‘usrers’, ‘action’ => ‘view’, $subdomain]
    );

I am not sure it is correct way.