Domain level 301 redirect using _redirects & Jekyll

Our site was developed using and we’ve recently acquired and want to use it as our primary domain.

I have both domains registered externally added to Netlify.

Under Site Settings > Domain Management I have as the primary domain with “redirects automatically to the primary domain”

I have and listed as Domain Alias.

I want to do a 301 redirect for all pages so* is used in all instances.

I’ve created _redirects and it’s in my root folder and it contains the following …

Redirects from what the browser requests to what we serve

When I visit the the url remains the same, I’m expecting it to be .au only.

Hey @fz22gq

As per the Redirects and Rewrites documentation you need to save the _redirects to the publish directory. Is the root directory where you have saved the _redirects the directory that is published?

You will also want to follow the Domain-level Redirects documentation and create a wildcard rule so all paths are rewritten to the new URL not just the domain root.

Hello, my repository is and it’s saved in the ftsoau folder.

I’ve read the documentation and wasn’t sure exactly what I had to do. I didn’t see an example relating to my scenario - hence the support question.

Unfortunately the repository is private

The file is in the root folder.

Is the root directory the directory that is published? What directory is set as the publish directory in the site build settings?

I see, that is _site/

I’ll move the “_redirects” file there, thanks.

Would this be the content in the _redirects file?* 301!

That is correct, except you shouldn’t need http://, only https:// as all http:// is automatically rewritten.

I’ve tried clearing cached and redeploying, which was successful, although I still don’t see the redirects working.

The _redirects file is in the _site folder and it contains …* 301!* 301!

Do you see something like this at the top of the deploy log?

Have to tried downloading the deploy to see if the _redirects file is there?

Without knowing how you are building the site this is only a guess, but it is possible the _site directory is created during the build process and anything in it overwritten. If this is the case, you may need to append a command such as cp _redirects _site to the build command to ensure the file is in the deploy directory.

I don’t see anything at the start of the deploy log to suggest a redirect rule has been processed.

I’m autopublishing if that helps?

The _site folder exists in my local machine, but I don’t see it in Github, everything else is there.

I don’t see the option to download the deeply to verify the file exists.

Apologies for the vague answers, I’m inexperienced with Netlify and Github, I know just enough to get the site done.

I’ve added that line as you suggest, is this OK?

The deploy details page has changed a little since my previous screen capture. This is what you would look for now:

That build command won’t work. You would need jekyll build --trace && cp _redirects _site (assuming jekyll overwrites _site during build which I do not know as I don’t use it.) You may want to look at the Jekyll Documentation to see if there is another/better way to accomplish this.

OK, I was able to download the zip file, no there’s no _redirects file in there.

The log showed … No redirect rules processed

The deploy failed with that line added.

Unfortunately I do not know enough about Jekyll to provide a solution at this point @fz22gq.

From what I have read, Jekyll may treat files/directories starting with an underscore differently.

I know there are community member here with far more Jekyll knowledge and am sure they will have an answer for you in due course.

Thanks for the assistance. I’ve edited the subject to include Jekyll hoping to get the relevant eyes.

Every file or directory beginning with the following characters: . , _ , # or ~ in the source directory will not be included in the destination folder. Such paths will have to be explicitly specified via the config file in the include directive to make sure they’re copied over:


Now we’re getting somewhere. I’ve removed _site/ from the .gitignore file, will deploy again now.

Deploy successful, the _site folder now exists, as does the _redirects file.

Still showing “no redirect rules processed” in the deploy log.


Looking at your previous build, it seems that there was a redirects.json file added but did not have the proper contents (and the file name should be _redirects).

Do you mind trying a whole different strategy here? Let’s try to add the redirects through a netlify.toml file. This file-based build approach will allow you to set/override multiple options on your build, being one of them the redirects.

In a netlify.toml file, each redirect has its own section. In your case:

  from: "*"
  to: ""
  force = true

  from: "*"
  to: ""
  force = true

The default HTTP status code for redirects is 301 so you don’t need to specify it there.

Can you try to apply this inside your netlify.toml file which needs to be created at the root level of your app.

With this approach you can remove the “cp” from your build command.

Can you try this out, please?

1 Like