Subdirectory and publish directory, redirection

Hi, thank you for netlify this is a wonderful tool.

I’m facing a weird issue about redirection setting on netlify.toml. I made a very simple repository to reproduce this issue.

and this is the instance.: hopeful-spence-2f41dd


redirection doesn’t work when I wrote base and publish and redirect on the same netlify.toml file.

Step1: without base setting

  publish = "publish/"

without base setting, netlify can build this and detect one redirection setting(this’s fine.)

Step2: with base setting.

Let’s move the publish directory to a subdirectory.

  base = "subdirectory"
  publish = "publish/"

Though I just added 1 line about base setting, netlify cannot detect redirection.

Step3: puting the config on publish directory

This is additional information. When I copy netlify.toml on publish directory,

The redirection works!

I know it’s not good to put 2 netlify.toml in a repository and we can use _redirect file as a workaround.
But I’m suspecting this’s a bug netlify watching the wrong place config file.

Hi there! We’re glad to hear you’re enjoying Netlify and thanks for this report :slight_smile: One issue that may be getting in the way in Step2 is that your base directory doesn’t have a / after it and the publish directory is not relative to the root, as described here:

Does the index.html publish in that case?

The Step3 you mention is very interesting and weird- I’m guessing that the inner .toml file is being picked up, based on the issues I described above with the outer .toml. It would be interesting if you switched the redirects- from index.html to index2.html. My guess is that even though the redirect is being loaded, it is not doing anything- just publishing the index.html file in the “root” (where the inner .toml is).

Anyway, thanks again and let us know if there’s anything you’d like our help with going forward!

1 Like

Thank you for your reply. I’ve tried.

  1. set trailing slash after “base”.
  base = "subdirectory/"
  publish = "publish/"


Still netlify do not detect redirect rule.

  1. and set publish directory as relative to root
  base = "subdirectory/"
  publish = "subdirectory/publish/"

Netlify could not build with this setting…

4:40:05 PM: failed during stage 'building site': Deploy directory 'subdirectory/subdirectory/publish' does not exist

Hi, @mogya. If you change the publish directory in netlify.toml then you must also put a netlify.toml (or _redirects) file in the base of the publish directory.

The redirects in the first netlify.toml, the one which changes the base directory, will never be read.

There is a more detailed explanation of this behavior here:

If there are other questions about this, please let us know.

1 Like

Wow, that’s a spec? Okay I see!
I’m happy if you write clarify this thing on document page. It’s difficult to find the page on QA forum.

I see what you are saying! Thanks for pointing this out :muscle:

1 Like