subdomainwildcard-subdomainexpress-subdomain

Wildcard Subdomain help needed


I want to dynamically create subdomain sites such as "user1.example.com", "user2.example.com" and serve static html and css based on subdomain. For a real world example blogger.com servers html and css for different users on blogspot domainl link https://althouse.blogspot.com/. I want to do exactly the same thing like blogger.com does.

Questions:


Solution

  • What you are trying to achieve cannot be done with S3 alone.

    Assuming you have already created a Wildcard DNS record for your domain name, you will need to write some server-side code to achieve this. On your server, you will check for the Host header and accordingly serve the correct html page based on that.

    Crude sample code for Node.Js + Express will look like:

    if (req.host === chetan.blogspot.com) {
       return res.render("chetan.html");
    } else if (req.host === jain.blogspot.com) {
       return res.render("jain.html");
    }