How to get cakephp Deliver content to different subdomains?

I am creating a portal that will have different cities.

When someone comes to the site, I want them to choose a city, and then continue

to

http://city1.site.com

or

http://city2.site.com

can this be done using a single database and cakephp installation?

+3
source share
1 answer

Yes it is possible.

Basically in your DNS you should allow * .site.com to be hosted on the same machine. Thus, no matter which subdomain you type, the machine will be the same.

example dns entry:

*   A   10.0.0.1

Then in the virtual host declaration you should put

<VirtualHost *>
        DocumentRoot /var/www/path_to_site
        ServerName site.com
        ServerAlias www.site.com *.site.com
</VirtualHost>

, , , i.e. something.site.com city.site.com .

php ( AppController) .

, .

( ): , . , :

cite1.site.com

AppController - :

class AppController extends Controller {
  function beforeFilter(){
     $host = explode('.', $_SERVER["HTTP_HOST"]);
     $subdomain = $host[0];
     Configure::write('city', $subdomain);
     $this->City->getId($subdomain); //function in City model fetching City ID by city name
     ...
  }
}

, , , .

+5

Source: https://habr.com/ru/post/1758849/


All Articles