Support Forums

Subdomain redirect

Hi :slight_smile: I have subdomain https://rust.patrikbraborec.com and that subdomain works fine but when I go to https://www.rust.patrikbraborec.com then it does not work. I would like to redirect from https://www.rust.patrikbraborec.com to https://rust.patrikbraborec.com - I did not find any solution for this. Is it possible to do it? Thanks!!

I’m curious. What use case are you trying to target by using a sub-sub-domain?

However, to answer your question, the domain that you set as ‘primary’ domain in your Netlify dashboard is the one it automatically redirects to. How exactly have you set this up. The redirects should work automatically.

For example, when someone types into a browser www.rust.patrikbraborec.com then it does not work as I expect (the result is an empty page with “not found”).

When someone types into a browser rust.patrikbraborec.com then it works fine.

I have set the primary domain to patrikbraborec.com and www.patrikbraborec.com redirects automatically to the primary domain.

I would expect the same behavior with the subdomain. Is it possible?

Not from Netlify dashboard, I guess1. You can add a redirect in your netlify.toml file, or use JavaScript to redirect.

1You can try this, though, I’m not sure if it’ll work. You can add a CNAME record in Netlify DNS with the name www.rust and value as rust.patrikbraborec.com.

I added CNAME record and it does not work. :confused:

I would like to add a redirect to netlify.toml but I do not know where to add this file. You know, I am building rust.patrikbraborec.com from github branch rust.

I tried to add netlify.toml file to my repository but it does not work:

from = "https://www.rust.patrikbraborec.com"
to = "https://rust.patrikbraborec.com"
status = 200
force = true

But, maybe I am doing something wrong.

I had thought so.

So, the netlify.toml file should to in the base path (same path as package.json) of that repository.

Try it this way:

  from = "https://www.rust.patrikbraborec.com/*"
  to = "https://rust.patrikbraborec.com/:splat"
  status = 301
  force = true

Unfortunately, it does not work :confused:

Try replacing 301 with 404.

Yes, I tried :smiley: but still nothing…

I do not know, maybe I am doing something wrong

Well, I have a last option and that is to use plain HTML. You can create an index.html in the root of your www.rust.patrikbraborec.com website. and add the following code to <head>: <meta http-equiv = "refresh" content = "0; url = https://rust.patrikbraborec.com"/>

There’s yet another method actually, but, that’d involve JavaScript. So, it won’t work for those with JavaScript disabled, but, first, try the HTML one.

But I do not have access to www.rust.patrikbraborec.com, or have I?

Because, you know, I am using branch subdomain from which I am building website rust.patrikbraborec.com and I cannot put anything to www.rust.patrikbraborec.com. I suppose, I should change DNS record but I think I cannot do it in netlify dashboard.

Well, I thought you had another branch at www.rust. If not, how did you even get the www version working then?

Well, to be honest - I do not know. Yesterday, I created some domain alias (to achieve desired behavior) and it created some DNS records which I am not able to delete now.

I bought the domain on netlify. Can I somehow edit DNS record from CLI? I think it would solve problems with redirect as well as with delete of some DNS records I am not using (I cannot delete them from netlify dashboard).

Sorry for troubles. It is probably my mistake

From what I know, DNS is only available through the Dashboard. Maybe someone from Netlify can get the redundant DNS records removed for you (not sure, but, you might have to mention which ones).

www-rust.patrikbraborec.com can be deleted.

Great. So, that fixes it, I guess.

Would you like that record deleting? :slightly_smiling_face:

Yes, please! :slight_smile: Thank you!!!

Marked for deletion, @patrikbraborec. Thanks for bearing with us!

1 Like