Redirect file for jekyll processed without errors during build but not producing 301s

I’ve added a _redirects file to my jekyll site, attempting to 301 some URLs to my new domain for the project. Both domains are purchased through Netlify. I see that the redirects are being recognized during the build, but they do not seem to be functioning. I’ve included the file in my config so that it reaches the build folder (_site). I’ve tried numerous variations of the format shown in the Netlify docs but still struggling to make it work.

My file looks like this:


The file is named _redirects and is placed in the _site build directory of my project, which is being built through direct connection to my Github account.

I must be missing something obvious here? Any help much appreciated!

Seems like a reasonable setup, assuming you have both names set on the same website in the domain settings page. If you’d like to tell us a real name, we can check your config and advise, but without more details, hard to understand where your setup would have failed.

Hey, thanks for the pointers above. I was able to resolve the problem and wanted to update this thread in case other folks are searching for ideas:

  1. My first problem was that while my redirect file was being output to _site locally, there was clearly some difference with the build on Netlify that was causing it to not output properly on production. Being as I was too lazy to work with Docker to troubleshoot locally, I updated my build command in Netlify to jekyll build && cp _redirects _site/_redirects to ensure that it was copied over to _site on Netlify.

  2. I still had some redirects that weren’t working, which was confusing because some redirect rules were working fine at this point. I figured out that it was because I was ignorant to the shadowing and force rules of Netlify, meaning that I needed to append 301! to my rules if I wasn’t removing the page I wanted to redirect.

E.g. this rule:
/my-old-post /my-new-post

Did not work if I didn’t remove the /my-old-post file. “duh” I know :stuck_out_tongue:

/my-old-post /my-new-post 301! solved this issue.

1 Like

Great finds, and thank you SO much for the follow-up so others who see this problem in the future, will also find your solutions :slight_smile:

Jekyll does have QUITE some opinions on files that can be in _site and will “chew up and spit out” your _redirects file.

I’ve found it to even have problems with that file in your repo (e.g. next to _config.yml) and so I usually go a step further and call it “redirects.txt” (since that isn’t a config-looking filename, I guess?) before making the copy.

1 Like