3
11 Comments

Using Clients Domain to show my product

Hello Dev community,

I am in the process of building an e-commerce system. My product will assign a client_id for any business register with my domain. I could fetch the product and category using the client_id.

I would like to have my client redirect their domain to my product (the browser should not redirect and show my product domain. But the browser should show the client's actual domain with my product in it).

How could I achieve it. I am kind of stuck at this point.

Any help is appreciated.

  1. 1

    The client has to setup their DNS server for their domain to point to your servers. After that, the requests at their domain will go to your servers and will have the "Host: ..." header set to their domain. Your app will then have to determine the content they will display by looking for the association between the host and client_id in your database.

    But to be absolute zero config from the client side, it isn't doable with a custom domain. Another solution, especially for demos, to reduce friction (because new clients might not want to fiddle with their DNS settings just to try out your product. Switching DNS to another solution is a pretty big commitment, especially if they already have an existing setup that works for them) would be to go for client subdomains on your domain (like Slack) -> example for a new Amethyst Platform company signing up, you would generate https://amethyst-platform.my-awesome-ecommerce-shop.com so I can explore what it can do, without any big commitment (or setup) on my side, and then when the time comes (if it comes), I'll pull the trigger and switch my main DNS too.

    1. 1

      I was thinking in the same direction with "header hostname" and associating it with a client_id. Wasn't sure if "hostname" will be part of all the requests (regardless of its orgin/DNS/NS config) . I will give it a try. In this way, I do not need to change the config in virtual_host file (this solution is more dynamic ). Thanks much @vladcalin

  2. 1

    I would like to do the server side redirect .
    Example : myproduct.com. {is My ecommerce product}
    My Client has domain : clientdomain.com

    When the user (Client's customer) enters clientdomain.com he should see my eCommerce product. It should be seamless for the user (he should not know if the
    clientdomain.com is using myproduct.com)

    Example : Like the same idea of http://glideapp.com/
    I could become a member of glideapp and direct my domain to their address. I am trying to achive the same.

  3. 1

    Would you like to do the redirect client or server-side? And do you already know where the user must be redirected to?

    1. 1

      I would like to do the server side redirect .
      Example : myproduct.com. {is My ecommerce product}
      My Client has domain : clientdomain.com

      When the user (Client's customer) enters clientdomain.com he should see my eCommerce product. It should be seamless for the user (he should not know if the
      clientdomain.com is using myproduct.com)

      Example: Like the same idea of http://glideapp.com/
      I could become a member of glideapp and direct my domain to their address. I am trying to achieve the same.

      1. 2

        I see what you mean, it's not really a redirect.
        Basically, you have a server running Nginx let's say.
        You configure a default virtualhost for all unconfigured domains, that will be for client domains.
        Then you have the one of your main site.
        Finally, clients will point the A record to your server and it's done.
        You can go further by writing a script to deploy SSL certificates (and renew them) automatically

        1. 1

          Thanks much @Gube . I will give a try.

        2. 1

          Hi @Gube,

          Thanks for the helpful advice. We're running into a similar problem, except with trying to connect client's custom domains and applying SSL certificates. Actually we were able to deploy the SSL, but now the site is available on 2 domains at the same time (the original subdomain and now the custom domain).

          Is there anyway to apply the SSL and to just have the custom domain version exist instead of the subdomain version as well?

          1. 2

            On nginx, you can use the server_name exampleDomainHere.com; clause to only allow given domains to be pointed to the client site directory.

            An example configuration could look like

            server {
            root /var/www/DirectoryForYourClients;
            index index.php index.html index.htm;

            server_name clientdomainone.com;
            server_name www.clientdomainone.com;
            server_name clientdomaintwo.com;
            server_name www.clientdomaintwo.com;
            # Note: You would update this file to include more, it can be done automatically with a PHP script, or anything else server-side really
            
            location / {
              try_files $uri $uri/ $uri.html $uri.php$is_args$query_string;
            }
            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            }
            

            #Under that would come the SSL configuration
            #Maybe use Estibot?

            }

            And you would still have a config file for your main site

            1. 2

              Not sure of the way to have the correct formatting on IH :/ @TeamIH

              1. 1

                Thank you @Gube I was able to understand it, will give it a shot over the weekend! Very much appreciated :)

Trending on Indie Hackers
How I grew a side project to 100k Unique Visitors in 7 days with 0 audience 49 comments Competing with Product Hunt: a month later 33 comments Why do you hate marketing? 29 comments My Top 20 Free Tools That I Use Everyday as an Indie Hacker 16 comments $15k revenues in <4 months as a solopreneur 14 comments Use Your Product 13 comments