Host Netlify site on path of domain managed elsewhere

Objective:
use example.com/pathname/ to host Netlify site, where /pathname/ is the root of my Netlify site.

example.com is a WordPress site hosted somewhere else.

What is working:

  • I can get the Netlify site to deploy to a path since that is what the other hosting company said they needed to make this work.
  • I’ve sort of followed along with this thread: TL;DR: bash script part of the build process to move all files in Gatsby’s /public folder to a /public/pathname/ folder.
    Deploy gatsby site to netlify with --prefix-paths - #3 by ovidiu1207

But
That script also moves the 404.html page which sort of breaks things. Netlify will build and deploy, but when users hit a route that doesn’t exist, they don’t get my website’s 404 they get Netlify’s generic 404.

I’ve Tried and didn’t work

  • Updating the script to move all but the 404.html.
  • Update the script to move all files then cd back into the /pathname/ directory and move the 404.html back up to the public/ directory.

This seems all wrong for what I want to do
I sense for what I want to do I’m going about this all wrong.

Hey Josh,

It sounds like you could add a redirect rule to forward any paths that result in a 404 to a different URL, see the docs for more information: Redirect options | Netlify Docs

In your case, you might be able to redirect /* to /pathname/404.

The implication is that your WordPress hosting company will not allow you to upload separate content via SFTP. If that is not the case, you could host your static files in a folder alongside your WordPress files.

@gregraven, yeah. This is an option, but I really want it to be my last option. I really really don’t want to leave the performance and netlify functions of Netlify.

Hey Josh - Sander’s suggestion may indeed work for you, though it will not return a 404 but instead a 301 to the 404 page. Still should show the content you want though :slight_smile:

The usual suggestion is to proxy from Netlify to the other site, but that wouldn’t work super well for a custom 404, or rather, you could use the 404 only for assets in /example/* using a pattern like Sander’s with the caveat that a) it would be a 301 redirect, not a 404 error as I mentioned and b) you’d probably want to let wordpress server handle the 404’s for anything not in /pathname…

I may be missing something, but would it work to set up your static files like this?


├── example.com
│   ├── 404.html
│   └── pathname
│       └── index.html

Hey @joshsmith01 , I’m looking to do something similar. Can you elaborate on what you/your WP hosting company did to serve the Netlify site on a path?

Sorry, I can’t give specifics. Not that it is top secret or anything, it’s just that I don’t know. I asked, Pagely, my hosting service for WordPress and where my domain is used to do it. Basically, I called in a support ticket and they did it all.

Sorry, I get a little over my head doing that kind of DevOpsy stuff. I know when I asked that had something already chambered and ready to go so I don’t think it was a big task for them.

Thanks for your reply Josh. I feel similar about the DevOps side of things, good thing we have providers like Netlify :wink:

For anyone finding this topic later — I did some more digging and found out about reverse proxying with Netlify, explained on Stack Overflow by @fool here: heroku - Reverse proxy same naked domain to different hosts - Stack Overflow

1 Like