Use different domains within a main website (city guide)

Asked

Viewed 84 times

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 as follows:

ID: 1 | City: Araxá | TAG: araxa | Access: www.siteprincipal.com.br/araxa Ex internal page: www.siteprincipal.com.br/araxa/contact

ID: 2 | City: Uberaba | TAG: Uberaba | Access: www.siteprincipal.com.br/Uberaba Former of internal page: www.siteprincipal.com.br/Uberaba/contact

ID: 3 | City: Ituiutaba | TAG: Ituiutaba | Access: www.siteprincipal.com.br/Tuiutaba Former of internal page: www.siteprincipal.com.br/Ituiutaba/contact

But I want to register and use a specific domain for each city (remembering that everything will be hosted within www.siteprincipal.com.br):

www.dominioaraxa.com.br => Ex de link: www. dominioaraxa.com.br/contact www.dominiouberaba.com.br => Link ex: www. dominiouberaba.com.br/contact www.dominioituiutaba.com.br => Ex de link: www.dominioituiutaba.com.br/contact

SUMMING UP: I want to host the site in the main domain (www.siteprincipal.com.br) but that people can access it by the domain name of each city (dominioaraxa, dominiouberaba, dominioituiutaba, etc...).

Any idea how to do this? By studying and working on HTACCESS and/or working on the DNS of each domain. Someone with experience in this to point the way?

Remembering that redirecting only DOES NOT ANSWER ME, because then the URL will stick to the link of the main site, and I wanted to show in each city the separate domain.

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

Thank you.

  • 1

    with Laravel you would make easy subdominios.

  • http://duvidas.laravel.com.br/forum/07-16-2014-route-group-com-subdominio-menos-para-www?page=1

  • .htaccess is the best way. I would go in this option, but since this would be an opinion, I’ll just leave a comment.

1 answer

2

Here is a simplified path without depending on the .htaccess:

  • PHP has the variable $_SERVER['SERVER_NAME'], which serves to indicate which domain the customer is using to access your website.

  • For this, set the server so that the same folder will serve multiple domains.

  • You must configure all DNS to point to the said server.

There, in PHP you can use various techniques, such as searching for the domain in DB, or use for example 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 overload of access to DB on every page, and this switch can be generated via meta-programming, to track changes in DB.

On the other hand...

If you manage it by .htaccess or even by configuring the server, could create more interesting situations, using mod_rewrite.

So you could serve each domain for a separate PHP, like araxa.php, uberaba.php, and these files could have only the variables necessary to set up the environment of the sites, and in them give a require in the main script that would serve all domains (if you have different code parts in each city).

I was just trying to give you an outline of some of the many possibilities. If applicable, give more details of specific needs, or work with each problem in separate questions, so you can have more complete answers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.