Adding multiple, custom domains

Surge intentionally support a single, custom domain per project. There are no short-term plans to add support for listing multiple domains in the CNAME file: publishing identical projects to multiple domains is an anti-pattern. (If you are concerned about redirecting to and from the www version of your domain, Surge takes care of this for you, for free.)

You can accomplish the same, desired result—making a project available at mutliple domain names—by redirecting your other domains, to the project’s primary domain.

This also improves how search engines percieve your site: publishing duplicate content (the exact same site published to multiple domains) is considered a negative; properly redirecting multiple domains to a primary location is the encouraged alternative.

Redirect to the primary domain

First, publish to your primary domain as normal:

surge ./path/to/my-project example.com

Then, redirect your second domain to your primary domain. This is done by publishing the second projects with an SEO-friendly redirect, which are a feature of Surge Plus.

This method is a more maintainable and SEO-friendly option than publishing the same project multiple times, as you won’t be duplicating your content on multiple sites.

To add a redirect for your second domain, create a ROUTER file in the root of the project. The contents of the ROUTER file will look something like this:

301   /         http://example.com

…which will redirect /, the root of your second domain, to your primary domain, example.com. You can even add multiple redirects, so more paths end up at their proper locations, with your primary domain:

301   /         http://example.com
301   /:title   http://example.com/:title

Now, you are ready to publish this project to your second domain. In this case, example2.com:

surge ./path/to/dist example2.com

Redirecting more than one domain

If you want to re-direct more than two domains, you could publish the same project with the ROUTER file, to multiple domain names you’d like to redirect (note that each of these will need to be upgraded to Surge Plus). To make this more efficient, you can alias the deployment to a Grunt task, Gulp taks, or npm run script, like in this package.json file:

"devDependencies": {
  "surge": "latest"
},
"scripts": {
  "deploy": "surge ./path/to/dist example2.com; surge ./path/to/dist example3.com; surge./path/to/dist example4.com"
}

Now, running npm run deploy will publish the site to example.com and example2.com, one after another. Since they all have a ROUTER file, each will use the same redirect rules and redirect back to your primary domain.