Serving multiple domains from my netlify app

Hi! Seeking help for

https://techinterviewcoach.netlify.app/ Custom Domain: techinterview.coach and datainterview.coach

I’d like to use https://techinterviewcoach.netlify.app (a jekyll website) to serve multiple domains

Example:

techinterview.coach should point to https://techinterviewcoach.netlify.app/tech
datainterview.coach should point to https://techinterviewcoach.netlify.app/data

The problem: when I visit techinterview.coach I am redirected to techinterview.coach/tech - the /tech shouldn’t be there (I do have a redirect from / to /tech in the _redirect file, but when I removed it / would 404)

These are my DNS records for A and CNAME:

  • techinterview.coach 3600 INA 104.198.14.52

  • www.techinterview.coach 3600 INA 104.198.14.52

  • techinterview.coach 3600 INCNAME Tech Interview Coaching

  • www.techinterview.coach 3600 INCNAME techinterviewcoach.netlify.app/tech/

@adielleci You could do this by configuring them as two separate sites in Netlify, both set to build from the same repository but having the Publish directory for one set to tech and the other set to data.

1 Like

Hi Nathan, thank you - I tried setting the publish directory to _site/tech and removing /tech from the DNS CNAME entries, but I still get redirected to Tech Interview Coaching - maybe a matter of DNS propagation?

@adielleci Have you triggered a rebuild and redeployment of the site?

Yes, including one that cleared the cache

I found out why the change in configuration (via the website) was ineffective - the netlify.toml overrode it with

publish = “_site”

That said, changing the publish to “_site/tech” breaks the website (as I should have realized it would) as /tech needs many files that are in _site

This means I won’t be able to only deploy _site/tech - I need _site and from there somehow to add the “/tech” that appears in the url

If I’m understanding correctly…

  • Your files are output into _site
  • There are shared files in _site
  • _site is set as the Publish directory and thus represents /
  • Your html is output into _site/tech/ and _site/data/
  • You want to serve the files in those sub-folders as if they were the root, (so you don’t see /tech/ in the url), while also still serving the shared files that are in the root

I’d probably just simplify the build structure myself if possible, but have you tried something like:

/*    /tech/:splat    200

It wouldn’t account for both tech and data, and redirects/rewrites can be tricky, but without the force (e.g. 200!), I’d expect that to rewrite any files that are requested at the root (and don’t actually exist there) to be retrieved from within the /tech/ folder.

Yes, there are folders in _site that are used by /tech/index.html

Examples:

  • _site/images
  • _site/js

etc

I guess an alternative would be to have

3 netflify websites

commonmaterial.netlify.app (deployed from _site)

techinterview.netlify.app (deployed from _site/tech, using materials pointing to commonmaterial.netlify.app)

datainterview.netlify.app (deployed from _site/data, using materials pointing to commonmaterial.netlify.app)

You could but if it were the single common build containing and building everything:

  • You would potentially be building each site 3 times
  • You would be deploying the tech and data folders to commonmaterial by virtue of deploying _site
  • Your site deployments now wouldn’t be atomic
  • You would still need to change all your shared asset references

I’m unfamiliar with Jekyll specifically, but when I said “I’d probably just simplify the build structure”, I mean that you could add some additional utility scripts that execute before/after your main build script to manipulate your site files into a single clean final structure, removing some complexity from deployment/references/redirects etc.

For example instead of a build that “produces all sites but only deploys one folder”, you could likely make it so that it “only builds one of the sites” and instead of building into a sub-folder like tech or data simply builds whichever site was targeted into _site. Thus the site files can reference the shared assets in a root relative fashion, as they’ll end up located directly with those assets.

Some example ways you could do this might be by pre-deleting a particular content folder in your build script so that it doesn’t get built, or post-build copying the files from your top level shared assets folder into the resulting build folder.

2 Likes

Thanks for the excellent debugging! @adielleci, don’t hesitate to follow up in the future if you have additional questions.