Deploy a React, Vue or static-site build

Build a front-end project locally, upload the output, add single-page app routing and long-lived caching.

TutorialIntermediate20 min to completeLast updated
On this page
  1. What you’ll need
  2. Step 1: Set the base path
  3. Step 2: Build
  4. Step 3: Zip the output’s contents
  5. Step 4: Upload and extract
  6. Step 5: Add routing for single-page apps
  7. Step 6: Test deep links
  8. Step 7: Force HTTPS
  9. Check it worked
  10. If something goes wrong
Level
Intermediate
Time
About 20 min
Steps
7
You’ll finish with
A working result, checked

7 steps

What you’ll need

  • A project that builds to static files
  • DirectAdmin access

A static build doesn’t need a Node.js app running on the server, so it’s fast and light on your account. You’ll build, upload and configure routing. Hosting static sites and JavaScript framework builds

Step 1: Set the base path

If the app will live at the domain root, make sure its base path is / (Vite: base: '/').

Step 2: Build

Run npm run build. Note the output folder (dist/, out/ or build/).

Step 3: Zip the output’s contents

Select everything inside the output folder and zip it.

Step 4: Upload and extract

Upload to public_html and extract, then delete the zip. How to upload and extract a zip file

Step 5: Add routing for single-page apps

Create public_html/.htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

Step 6: Test deep links

Visit an inner route directly, such as /about, in a private window, and refresh it.

Step 7: Force HTTPS

Add the HTTPS redirect above the routing rules. How to force HTTPS (redirect HTTP to HTTPS)

Check it worked

The home page and a directly visited inner route both load and survive a browser refresh over HTTPS.

If something goes wrong

What happensWhat to do
Blank page, console shows 404 for JS filesWrong base path in the build config.
Inner routes 404 on refreshThe routing .htaccess is missing or in the wrong folder.

Traxio accounts include SSH, Git, cron and PHP 7.4 to 8.4. Try the PHP hosting is £0.99 a month.

Where this fits: DirectAdmin hosting explains the control panel every Traxio account uses, with a tour and tutorials.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going