Use different domains within a main site (city guide)

0

I wanted a light for the following situation:

I have a main website (online guide) www.siteprincipal.com.br. In this site I have a table of cities where I register each one and I show the content in the following way:

ID: 1 | Location: United States | TAG: araxa | Access: www.siteprincipal.com.br/araxa Ex of internal page: www.siteprincipal.com.br/araxa/contato

ID: 2 | City: Uberaba | TAG: Uberaba | Access: www.siteprincipal.com.br/uberaba Ex of internal page: www.siteprincipal.com.br/uberaba/contato

ID: 3 | City: Ituiutaba | TAG: Ituiutaba | Access: www.siteprincipal.com.br/ituiutaba Ex of internal page: www.siteprincipal.com.br/ituiutaba/contato

However, I want to register and use a specific domain for each city like this (remembering that everything will be hosted inside www.siteprincipal.com.br):

www.dominioaraxa.com.br = > Ex of link: www. domainaraxa.com.br/contact www.dominiouberaba.com.br = > Ex of link: www. dominiouberaba.com.br/contact www.dominioituiutaba.com.br = > Ex link: www.dominioituiutaba.com.br/contato

SUMMARY: I want to host the site in the main domain (www.siteprincipal.com.br) but that people can access it through the domain with the name of each city (domainaraxa, dominiouberaba, dominioituiutaba, etc ...) p>

Any ideas how to do this? If studying and manipulating HTACCESS and / or manipulating the DNS of each domain. Anyone with experience in this to point a path?

Remembering that redirect only DOES NOT ANSWER me, because there the URL will get the main site link, and I wanted it to show the separate domain in each city.

Working with Linux hosting and programming using PHP and MySQL database.

Thank you.

    
asked by anonymous 28.06.2014 / 03:16

1 answer

2

Here is a simplified path without depending on .htaccess :

  • PHP has the $_SERVER['SERVER_NAME'] variable, which is used to indicate which domain the client is using to access your site.

  • To do this, configure the server so that the same folder serves multiple domains.

  • You should configure all DNS to point to that server.

In PHP, you can use various techniques, such as searching for the domain in the DB, or for example using a switch:

switch ( $_SERVER['SERVER_NAME'] )

{
   case 'www.cidade-um.com.br':
       $titulo = 'Cidade Um';
       $logo = '/assets/cidadeum.png'
       break;

   case 2:
       $titulo = 'Cidade Dois';
       $logo = '/assets/cidadedois.png'
       break;

   // ... e assim por diante ...
}

The advantage of the switch is to avoid DB access overload on every page, and this switch can be generated via meta-programming to track changes in the DB.

On the other hand ...

If you manage this by .htaccess or even by server configuration, you could create more interesting situations using mod_rewrite .

So you could serve each domain by a separate PHP, such as araxa.php , uberaba.php , and these files could have only the variables needed to configure the site environment, and give them a require in the main script which would serve all domains (if you have different code parts in each city).

  

I tried to sketch out some of the many possibilities. If so, give more details of specific needs, or work with each problem on separate questions, so you can have more complete answers.

    
28.06.2014 / 03:48