Sanyukta Suman Logo Sanyukta Suman
Blog Post Thumbnail
Image credit: Source

Connect Sub Directory from the GitHub repo to Vercel Domain

Published on September 5, 2025

If you're deploying a static site on Vercel and getting a 404: NOT_FOUND error, it usually means Vercel can't find the entry point for your website (typically index.html). Use this guide to systematically check and fix the most common causes.

Step 1: Verify Vercel Project Settings

This is the most common issue. By default, Vercel looks for your website files in the root of your repository. If your files are in a different folder, you must tell Vercel where to look.

  • Action: Go to your Vercel project's dashboard. Navigate to Settings > General.
  • Check Root Directory: If your index.html file is inside a subfolder (e.g., campaign_optimizer), you must set the Root Directory field to that folder name.
  • Check Output Directory: If you are using a build process (like Vite or Parcel), you must also specify the Output Directory (e.g., dist or build). This tells Vercel where to find the final, minified files after the build is complete.

Step 2: Check Deployment Logs for Errors

The Vercel logs are your best friend for debugging. They show you exactly what happened during the build and deployment process.

  • Action: Go to your Vercel project's dashboard. Click on the Deployments tab and select the latest deployment.
  • Look for Failures: In the Build Logs, check for any red error messages. The logs might indicate that a file is missing, a command failed, or there was a typo in a configuration file.

Step 3: Confirm the File Structure with the "Source" Tab

The "Source" tab shows you the final file structure that Vercel is serving. It's a critical tool for verifying if your files were deployed correctly.

  • Action: In the deployment overview, click on the Source tab.
  • Verify index.html: Ensure that your index.html file is present in the expected location. If you have a Root Directory set to campaign_optimizer, your index.html file should appear at the top level of the file tree shown in this view. If it's not there, it means your build or file configuration is incorrect.

Step 4: Implement a vercel.json Rewrite Rule (The Ultimate Fix)

If your index.html is in a subfolder and the above steps haven't worked, the most reliable solution is to explicitly tell Vercel to serve it using a vercel.json file. This overrides Vercel's default routing behavior.

  • Action: Create a file named vercel.json in the root of your repository (the same level as your .git folder).
  • Add this code:

    {
      "rewrites": [
        {
          "source": "/(.*)",
          "destination": "/campaign_optimizer/index.html"
        }
      ]
    }
  • Commit and Push: Save the file and push the changes to your Git repository. Vercel will automatically trigger a new deployment and apply this configuration.

This vercel.json file tells Vercel to redirect all incoming requests to the specific index.html file in your campaign_optimizer folder, no matter what the URL is. This is the fix that worked for your specific situation and is an excellent solution for serving a static site from a subdirectory.