Forwarding subdomain to a path

Hi, I have created a new site at brhn.me hosted at netlify. Now I want to configure subdomain “bn.mydomain” in a way that internally it will load all contents from a subpath of main site.

“bn.mydomain/sample-post-in-bangla-language” would actually load “mydomain/bangla/sample-post-in-bangla-language”. URL will be shown as “bn.mydomain/sample-post-in-bangla-language” (Not a 302 redirect)

I am just wondering if this is possible in netlify. I did this with wordpress not sure how to do it here.

This challenge involves two part
First is to configure “bn.mydomain” to be forwarded to “mydomain”. Second part is rewriting url “bn.mydomain/*” as “mydomain/bangla/splat”

Is is possible here. If anyone has done similar, please let me know

Howdy!

Should be possible using this workflow:

  1. deploy the content on your main site under the /bangla/ path. This means you’ll deploy your usual content PLUS the content for /bangla/

  2. create a proxy redirect rule for that hostname. This article about how to set up your site for this kind of operation may be useful as you plan/design the layout, even if you don’t use multiple sites or repositories: [Common Issue] Can I deploy multiple repositories in a single site? . Deploy this rule in advance! Here’s a sample that should work for your fake example hostnames:

https://bn.mydomain/* /bangla/:splat 200!

This will leave the browser pointing at the original URL rather than the rewritten one. Since you use one site, you don’t have to actually proxy to a second one (though you could as the article I linked in #1 showed), so your “rewrite” will just be to the local path, and will only be activated for requests to the subdomain.

  1. point the DNS for that hostname to us (to the existing site): https://www.netlify.com/docs/custom-domains/#manual-no-www

  2. put subdomain in place on your site’s Domain Settings page as a domain alias (https://www.netlify.com/docs/custom-domains/#domain-aliases - aka “additional hostname for site”)

  3. await SSL certificate update for that new hostname

  4. ???

  5. profit!

1 Like

How about forwarding a path to subdomain? I’ve some similar situation in here,
for example that my domain is https://www.example.com/ and my website content is available in the domain path https://example.com/blog . I want to make my website content available at https://blog.example.com .

@afnizarnur, this works with the following redirect rule:

https://blog.example.com/* https://example.com/blog/:splat 200

For example, the address bar of the browser would show: https://blog.example.com/post-1234

The content shown, however, would be for the URL: https://example.com/blog/post-1234

Also, note that redirect rules are tested in the same order they appear in the file and only the first matching rule will apply. (There is one exception: 301 redirects trigger a new HTTP request at the new URL which, in turn, restarts the redirect checks).

Putting this type of rule (a rule rewriting a subdomain) before other rules which reference the same path (the path /blog in this case) worked well in my testing. This might vary from site to site as the case by case requirements may differ.

Additional note: This also requires adding that subdomain to the domain aliases under the domain settings for the site.

1 Like