If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Connect multiple domain names to one system

Started by ZoriWser, Dec 08, 2022, 09:50 AM

Previous topic - Next topic

ZoriWserTopic starter

Our project based on Yii2 is in progress. It is quite similar to www.insales.com, with the exception of mini-sites replacing online stores. In other words, there will be multiple sites within one system, similar to FB groups.

One question we have is how to connect domains to these sites. For instance, when a user visits www.site1.com, it should open the corresponding website. All settings for these websites will be saved in a database, meaning that they will not exist physically. Instead, there will be predefined templates and display settings.
  •  


Lucatall

I would like to inquire whether the sites will be stored on the same hosting within the same database. To proceed, my suggestion is to purchase two domains and bind them to the IP address of the hosting. In the hosting settings, you can bind the desired domain name to the selected folder.

If you wish to display the same folder at all addresses, you will need to work with .htaccess. Alternatively, each domain can have its own folder at the same level, sharing the same framework level. Every site has its unique entry point (index.php), along with public folders such as assets and uploads. Finally, customization of the URL manager is necessary.
  •  

merlinraj

The code snippet  involves using either $absoluteHomeUrl = Url::home(true), $_SERVER['SERVER_NAME'], or $_SERVER['HTTP_HOST'] to perform a certain action. In general, more information on this topic can be found by conducting a Google search.
  •  

Yana

To connect domains to the mini-sites within your Yii2 project, you can implement a domain mapping feature. When a user visits a specific domain, such as www.site1.com, your system needs to retrieve the corresponding website settings from the database.

First, ensure that all necessary domain records are properly configured in your DNS settings, pointing to the IP address of your server.

Next, within your Yii2 project, you can set up a route controller that handles incoming domain requests. This controller should retrieve the requested domain name and query your database to fetch the corresponding website settings.

Once you have retrieved the settings, your system can apply the predefined templates and display settings associated with that particular mini-site. This way, when a user accesses www.site1.com, they will be presented with the website specific to that domain.

By leveraging Yii2's powerful database capabilities and routing system, you'll be able to efficiently handle domain connections and deliver dynamic mini-sites to your users.

Additionally, you may consider creating a domain mapping table within your database to store the associations between domains and mini-sites. This table can have columns for the domain name and the corresponding website's settings or template ID.

When a user visits a domain, your application can query this mapping table to retrieve the relevant information. This provides flexibility as you can easily update or add new domain-to-website mappings in the future without changing the codebase.

To handle the domain mapping functionality, you can utilize Yii2's routing features. You can define a specific route that captures incoming requests with dynamic domain segments. Within the corresponding controller action, you can fetch the requested domain and use it to retrieve the associated website settings from the database.

Furthermore, to ensure consistent user experience across all mini-sites, you can design a set of predefined templates and display settings that can be applied to each site based on the retrieved information from the database. This allows for flexibility while maintaining a consistent brand identity and design.

Implementing a domain mapping solution in your Yii2 project allows for easy management of multiple mini-sites within a single system, providing a seamless and dynamic experience for users accessing different domains.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...