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.

IntermediateAbout 20 minutes7 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

Steps

  1. Step 1: Set the base path

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

  2. Step 2: Build

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

  3. Step 3: Zip the output’s contents

    Select everything inside the output folder and zip it.

  4. Step 4: Upload and extract

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

  5. 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]
  6. Step 6: Test deep links

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

  7. 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.3. Try the PHP hosting is free for 30 days with no card, then £0.99 a month.

Popular

Tip: press / to search from any pageSee all results