Hi, @clottman. The redirect didn’t work because it will be a 301 (unforced) by default. To force it, add the 301 (again, this is the default if no status is specified and follow the status with a literal exclamation mark (
In other words, make the rule like this instead:
/readme.md / 301!
The original rule will redirect only if
/readme.md doesn’t exist (but it does). The rule with
301! forces the redirect even when the file exists.
Finally, as far a simply excluding the file itself, simply delete it as part of the site “build and deploy”. Netlify only deploys the files it finds in the “publish directory”. If you delete the file before we publish the deploy, it won’t be part of the site.
So, if you have no build command, just make this your build command:
If you want to delete other files (like a file named
file.jpg in the subdirectory
example), you can just add them to the
rm command (this build image is running Ubuntu Linux) like so:
rm readme.md example/file.jpg
If you decide you do want a build command in the future (like
hugo as a simple example) you can append the
rm command to the build command with a “logical and” like so:
hugo && rm readme.md
You might ask why not use a semi-colon to separate the build command and the delete command like so:
hugo ; rm readme.md
The reason for the “logical and” (
&&) instead of the command separator (
;) is so that the build stops if the original build command fails. If you use the semi-colon, the build command might fail but the
rm command will return a success. It is the return value of the full list of commands which determines if the build image believes it was a successful build or not. If you use the semi-colon, Netlify will treat all builds as successes, even when they fail. Using the “logical and” prevents this “false success” issue.
To summarize, you can either a) use a slightly different redirect or b) delete the file from the build system before we publish the site.
If there are other questions, please let us know.
EDIT: I just wanted to add that I agree that, clearly, Soul Patch is the best boy!