Redirecting path to subdomain

Normally, I’d use NGINX to handle a redirect where the new url points to the location where the files are. Do I need to provide a domain to achieve a 301 redirect?

Essentially, my original path is this. I’ve added a file called netlify.toml:

# A redirect rule with all the supported properties
[[redirects]]
  from = "/apps/*"
  to = "https://apps.elastic-joliot-524d89.netlify.com/:splat"
  status = 301
  force = true
  headers = {X-From = "Netlify"}

The redirect works but I expect to see the page. Is this correct? Do I need to add a custom domain before seeing the page? Not sure I can redirect to a sub domain of a sub domain (elastic-joliot-524d89) :smile:

PS: Im using Nextjs

“expect to see the page” - what page is missing? That redirect should send to https://apps.elastic-joliot-524d89.netlify.com/xero/ with a 301 status. If you mean instead to show the page rather than redirecting, you want a rewrite; use status 200 instead of 301 :slight_smile: (more details here: https://www.netlify.com/docs/redirects/#proxying)

Your “headers” won’t do anything on a 301 redirect (but it will with a 200!)

1 Like

Hi @SylarRuby,

I just took a look at https://app.netlify.com/sites/elastic-joliot-524d89/deploys/5d2de27adecb1500076ab31c and you don’t have a netlify.toml or a _redirects file. Do you have the netlify.toml with the redirect in the root of your repo? Note that @fool’s point is also correct int hat the custom header only works for proxied requests.

1 Like

Many thanks for the replies. I once had that .toml file in. I was lost so I removed it, added a custom domain and forget about the /apps and use /xero instead. It’d be immensely greatful to have the original plan to work: /apps/* to https://apps.mayneweb.com/:splat

“I’m texting from mobile”

I’ll try the suggestions later and report my findings. Thanks

1 Like