P
P
Pavel Zhukau2016-12-31 18:08:56
Domain name market
Pavel Zhukau, 2016-12-31 18:08:56

How to link domains to wildcard subdomains?

Hello everyone, this task has become, each client has access to the address, client-url.mydomain.com
That is, on the face of a regular wildcard, I catch what the subdomain was, and already pass it to the controllers, the controller looks at what the subdomain was, looks at the client, and already depending on this something shows on the screen. I have such requests for both get and post for these same wildcards.
Now the question is how to implement it so that the client can bind his domain to his address, that is, besides, client-url.mydomain.com and use it already through the domain. I tried to look at the very beginning of the routes file which request, if Request::get_host() contains the address of my domain, then we have open subdomains and go further, if not, I take the domain, look in the database, if the client specified this domain, then okay, I go further to the controllers, and in each action I look at the domain, whether it is a domain or a subdomain, and then I work with this client. Everything was cool, except for two but, the code is wildly miserable, and in this way GET requests work, but already with POST everything flies.
Please tell me where to dig, what to look for in order to implement this.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-01-06
@NikesDark

Too many conditions.
1. Implement a single algorithm for working with a domain, no matter what your domain or service domain is. The script always goes to the database and sees who its owner is.
2. Most likely you do not store the entire domain, but only part of it (I'm talking about a subdomain), this exception can also be easily handled
3. Work with http_host, it's better to use routes only in relative path mode (of course, if all sites are typical)
4. Create a separate class, wrap it in a service and you will be happy. This is exactly what I did in my project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question