How to Redirect a Subdomain to an External App

i have a blog hosted on netlify pretty simple to setup… i have set it so that my DNS is managed by netlify.

i can create subdomain from the netlify control panel, but i dont know how to set it up so that a subdomain can point to a separate app (for example: hosted by aws)

currently when i create a subdomain (test.my-blog.com), it simply points to the main site (my-blog.com), which is the same thing as not having a subdomain.

i am looking at the documentation and it seems unclear to me so it would be helpful if someone can point me in the right direction or to an example similar to what i am describing.

hi xoron,

i think what you need is a redirect:

thanks for the reply.

looking at the documentation in the link provided i created 2 new files described as the following:

_redirects:

/testing-redirect   https://www.petsofnetlify.com
https://pets2.my-blog.com   https://www.petsofnetlify.com

i think this file is not working or has something not configured correctly. i have placed the file in the root directory of the project. none of the redirects work at all.

https://pets2.my-blog.com display the content of what is on https://my-blog.com. the same as not having a subdomain.

netlify.toml:

[[redirects]]
  from = "/pets"
  to = "https://www.petsofnetlify.com"
  status = 200
  force = true # COMMENT: ensure that we always redirect
  headers = {X-From = "Netlify"}
  signed = "API_SIGNATURE_TOKEN"

[[redirects]]
  from = "https://pets.my-blog.com"
  to = "https://www.petsofnetlify.com"
  status = 200
  force = true # COMMENT: ensure that we always redirect
  headers = {X-From = "Netlify"}
  signed = "API_SIGNATURE_TOKEN"

this file is working. so when i go to https://pets.my-blog.com i am redirected to https://www.petsofnetlify.com. (and the same for my.blog.com/pets).

but the behavior i am seeing is that the url is changed to: https://www.petsofnetlify.com… in the documentation here, it says “For security reasons, rewrites between Netlify sites belonging to different teams are not allowed.”… so i tried to change this to another url (assumming https://www.petsofnetlify.com is hosted on netlify).

so i made the change the netlify.toml file and now it is working as expected. (not: to also include the url path into the proxy i added /* and /:splat as further explaining here)

...

[[redirects]]
 from = "https://pets.my-blog.com/*"
 to = "https://my-aws-app.com/:splat"
 status = 200
 force = true # COMMENT: ensure that we always redirect
 headers = {X-From = "Netlify"}
 signed = "API_SIGNATURE_TOKEN"

i hope this helps anyone else having a similar issue.

1 Like

Thanks for sharing this detailed write-up of what worked for you! Post like these likely will help someone searching for their own solution and I’m sure these future visitors will appreciate the detail you provided in your answers.

Thanks again for this follow-up, @xoron.