Skip to content

A React app often starts life on a temporary address supplied by a hosting service. That is fine for testing, but customers remember names, not strings of random letters. Connecting your own domain turns the project into a real site, and it is mostly a matter of getting four things to agree: where the built files live, which DNS records point to them, how HTTPS is issued, and how the host handles the routes your app creates in the browser.

This guide covers those four parts in order. It is written for the common case of a React app compiled into static files, which is how most tools such as Vite and Create React App produce a production build. If your project is server-rendered, the sibling guide on connecting a domain to Next.js will fit better. If you are still looking for a name to use, start from the domain search.

What you are actually publishing

When you run the production build of a React app, the tooling produces a folder, often called build or dist, with an index.html file, JavaScript and CSS bundles with hashed names, and any static assets. There is no application server in the picture. The browser downloads index.html, then downloads the scripts, and React runs on the visitor's device to draw the page and handle navigation.

That has three consequences for a custom domain:

  • The host only has to serve files and answer for your domain name. Any static-capable host will do: a front-end hosting platform, an object store with a CDN in front, or a plain web server.
  • Routes such as /pricing or /account/settings do not exist as files. The router inside your app creates them, so the host needs a rule that sends unknown paths to index.html.
  • The app talks to APIs from the browser. If your API is on another domain, it must allow the new site address in its cross-origin settings.

Understanding that split makes the rest of the steps easier to reason about, because each problem belongs to exactly one layer: DNS, hosting, HTTPS or the app.

Choose where the files will live

The table compares the usual options by what the domain connection involves.

Hosting option What you configure Who issues HTTPS Good fit when
Front-end hosting platform Add the domain in project settings, create the DNS records it shows The platform You want the quickest path and automatic deploys
Object storage with a CDN Attach the domain to the CDN, create a CNAME or ALIAS to the CDN hostname The CDN, or a certificate you attach You already use that provider for other assets
Your own web server Point an A record at the server, serve the build folder with Nginx or Caddy You, with an ACME client or a purchased certificate You want full control over the machine
Shared web hosting Upload the build folder, point the domain via the hosting control panel The panel, often with an automatic option The site is small and you already have the plan

Whichever you choose, the sequence is the same. You tell the host about the domain, you create records that lead to the host, you wait for validation and certificate issuance, and then you tidy up redirects and settings.

Step 1: Add the domain to your host

In the hosting dashboard, open the project and find the section for domains. Add the domain you want, with and without www if both should work. The dashboard usually shows a status such as pending and a list of DNS records to create. Keep it open.

Decide at this point which address is primary. A common choice is the bare domain, with www redirecting to it, but the opposite is equally valid. What matters is picking one and redirecting the other, so search engines and analytics see one site rather than two.

If the host offers to manage your DNS by taking over the nameservers, consider whether you want that. It is convenient, but it moves every record, including email, to a new place. When you only want the website to move, keep your existing DNS and add the records yourself.

Step 2: Create the DNS records

Open the DNS settings at your registrar or DNS provider. If you registered the name through us, the editor is part of the domain management area linked from the domains page.

A typical layout, with 203.0.113.10 standing in for a real address:

Name Type Value Purpose
@ A 203.0.113.10 Send the bare domain to the host
www CNAME hostname provided by the host Send www to the host
@ AAAA IPv6 address, only if provided Optional IPv6 support

Notes that save time:

  • Take values from your host's screen. They are specific to your project and can change.
  • A CNAME is an alias of one name to another and cannot sit beside other records at the same name. Because the bare domain always has records such as SOA and NS, it normally uses A, or ALIAS or ANAME if your provider offers them. The naming rules come from RFC 1034.
  • If an old record exists for the same name, edit or delete it. Two conflicting answers cause visitors to land on different sites.
  • Leave MX and TXT records alone. They run email and verification.
  • Consider lowering the TTL a day before the change, so mistakes can be corrected quickly.

Save, return to the host and request a re-check if the dashboard has a button for it.

Step 3: Wait for validation and HTTPS

Resolvers cache answers, so DNS changes spread gradually. Many changes are visible within minutes; plan for a few hours. While you wait, you can inspect progress with a lookup tool such as dig or nslookup, asking for your bare domain and your www name, and comparing the answers with what the host expects. A public resolver gives you an outside view.

When the host recognises the records, it requests a certificate for your names. On managed platforms this is automatic. If you want a certificate you manage yourself, for example one with organisation details or a particular coverage, the SSL page explains the choices. On a server you manage, install the certificate in Nginx or Caddy and configure automatic renewal.

For a plain-language explanation of why the padlock matters, read What is HTTPS?. Practically, test by opening both names over HTTPS in a private window and checking that the certificate lists your domain and has valid dates.

Step 4: Fix routing for a single-page app

This step is the one React developers meet most often, and it has nothing to do with DNS. With client-side routing, the URL /pricing is handled by JavaScript after the app loads. Navigate there by clicking a link and everything works. Open /pricing directly, or refresh the page, and the browser asks the host for a file named pricing. The host has none and answers with a 404 status.

The fix is a fallback rule: for any path that does not match a real file, return index.html with a successful status, and let the router decide what to show. Each host exposes this differently.

  • On platforms, there is usually a rewrite setting or a small configuration file in the project that maps all paths to index.html.
  • On Nginx, a try_files rule that tries the requested path and falls back to index.html does it.
  • On Caddy, a try_files directive with the same fallback does it.
  • On shared hosting, a rewrite rule in the server configuration file does the job.

Keep two details in mind. Real static files, such as scripts, styles and images, should still return their real content and should still return a 404 when they truly do not exist, so a missing script does not silently load the HTML page. And if your site has a few URLs that should return a genuine not-found response for search engines, handle them inside the app by rendering a not-found page, and consider whether the host can send the matching status. The meaning of status codes is defined in RFC 9110.

Step 5: Redirects and app settings

With the domain working, make both names end up at one address.

  1. Mark one name as primary on the host, and add a permanent redirect from the other.
  2. Test both names, plus a deep link, in a private window.
  3. Update the public URL setting in the project, which in many toolchains is a variable read at build time. Rebuild and redeploy after changing it.
  4. If the app is served from a sub-path rather than the root, set the base path in the router and the build tool so that assets load from the right place.
  5. Update the allowed origins on your API, for cross-origin requests, so that the new domain is permitted.
  6. Update callback and redirect addresses registered with sign-in or payment providers.
  7. Add or update the canonical tag and the sitemap if you maintain them, so that they use the primary address.

A reminder for search visibility: a single-page app that renders everything in the browser can be harder for crawlers than a pre-rendered one. If organic search matters, consider pre-rendering your key pages or moving to a framework that renders on the server, and follow general guidance such as the Google Search Central SEO Starter Guide.

Keep your email working

Email delivery depends on MX records, and sender checks use TXT records such as SPF, DKIM and DMARC. None of them are required for the website, so leave them as they are. The risk arrives when you move nameservers or accept a one-click setup that replaces the whole zone. Export or screenshot the zone first, and verify afterwards that mail still arrives.

If you intend to use mailboxes on the same domain, the business email page explains what a hosted mailbox needs. Planning the website and email DNS together avoids rework.

Limits and what to watch for

  • Stale caches. The site opens on one device and not on another. Wait out the old TTL, flush the local DNS cache, or test from a different network.
  • Old build, new domain. If you changed the public URL variable but forgot to rebuild, the app still points to the temporary address.
  • Cross-origin errors. After the move, API calls fail with a browser error about origins. Add the new domain to the API's allowed list.
  • Missing fallback. Every deep link returns a 404. Add the index.html fallback.
  • Mixed content. An HTTPS page that loads an HTTP script or image gets blocked. Update hard-coded addresses.
  • Leftover records. A forgotten A or CNAME record on www competes with the new one.
  • Proxy layers. An extra proxy in front of the host can interfere with certificate issuance until paused.
  • Caching of the HTML file. If index.html is cached too aggressively, visitors keep seeing an old version after a deployment. Cache hashed assets for a long time, but keep the HTML short-lived.
  • Registration expiry. A connected domain still disappears if the registration lapses. Use renewal reminders.

When something fails, check in layers: does the name resolve, does the host know the domain, is the certificate valid, does the route fall back, does the app load its data. Resist changing several layers at once.

A short worked example

An independent photographer builds a portfolio in React and wants it at lenspath.example.

  1. She runs the production build and deploys the build folder to a front-end hosting platform.
  2. In the platform's project, she adds lenspath.example and www.lenspath.example, and marks the bare domain as primary.
  3. At her DNS provider, she edits the bare name's A record to the value the platform shows, replaces the www record with the CNAME it gives, and does not touch the MX records for her mailbox.
  4. Fifteen minutes later the platform shows the domain as valid and issues the certificate.
  5. She opens lenspath.example/gallery directly and sees a 404, so she adds the platform's rewrite rule that returns index.html for unknown paths. The deep link now works.
  6. She changes the public URL variable, rebuilds, redeploys, and adds the new domain to the allowed origins of her contact-form API.
  7. She tests www in a private window and confirms that it redirects to the bare domain.

Total code changes: one configuration file and one variable. The rest was DNS and settings.

Summary

Connecting a domain to a React app means serving the build files from a host that knows your domain, pointing DNS records at that host, and letting HTTPS be issued. Add the domain on the host first, copy the DNS values it shows, use A or ALIAS for the bare domain and CNAME for www, and wait for validation. Then add the index.html fallback for client-side routes, redirect to a single primary address, update the public URL, allowed origins and callbacks, and rebuild. Leave email records alone, and keep an eye on stale caches, mixed content and renewal dates.

If you are ready to pick or bring in the name for your project, the domains page is the place to start.

Frequently asked questions

Does a React app need a server to use a custom domain?

A typical React app built for the browser is a folder of static files, so it needs a host that can serve files, not an application server. The custom domain points to that host through DNS records.

Why do deep links return a 404 error on my React site?

A single-page app handles routes in the browser. When someone opens a deep link directly, the host looks for a file at that path and finds nothing. Configure the host to return index.html for unknown paths so the app can take over.

Do I need to change my React code to use a custom domain?

Usually not. You may need to update the public URL, the base path, API addresses allowed by CORS, and any sign-in callback URLs that still point to the temporary address.

Can I use both example.com and www.example.com?

Yes. Choose one as primary and redirect the other to it with a permanent redirect, so that links, search results and certificates stay consistent.

Will connecting the domain affect my business email?

Not if you edit only the website records. Email uses MX and TXT records, which you should leave alone unless you are deliberately changing mail providers.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Start your website the right way

Register a domain, add SSL and set up business email from one place.

.com registration from $18.81 for the first year

Start with a domain

Keep reading

Website Guides

How to Connect Your Own Domain to a Next.js Site

A practical walk-through for pointing a custom domain at a Next.js app, from adding the domain on your host to DNS records, HTTPS and redirects.

10 min read

Website Guides

How to Connect Your Own Domain to a Laravel App

A practical walk-through for pointing a custom domain at a Laravel app, from DNS records and the public folder to APP_URL, proxy settings and troubleshooting.

10 min read

Website Guides

How to Connect a Custom Domain to Squarespace

A clear walkthrough for pointing a domain bought elsewhere at your Squarespace site: preparation, DNS records, www and root, email safety and final checks.

10 min read