http-redirecthttp-status-code-301netlify

How to make 301 redirect in Netlify work?


  1. I can't get the 301 redirect to work in Netlify at all (I've seen other answers, but it doesn't work).

  2. I've made the _redirects file and placed it in the root of my github ripo.

    https://some-domain.netlify.com/* https://www.mydomain.tk/:splat 301!

I expect it that when someone types this: https://some-domain.netlify.com/ he will be redirected to here: https://www.mydomain.tk , but that doesn't happen.

  1. I'm trying to redirect https://some-domain.netlify.com/ to https://www.mydomain.tk/portofolio/
    this didn't work either

Thanks for the help


Solution

  • The issue is that the _redirects file does not go to the root of your repository unless the root of your repository is your deploy path.

    The _redirects file must be placed into the root of your deploy path.

    example

    In the case below, the deploy directory after the build command is public in the repository.

    root
      ├ public
      | ├ _redirects
      | └ index.html
      ├ src
      └ lib
    

    Note: Remember that you can also put redirects in your netlify.toml file. The netlify.toml file does go in the root of the repository.

    netlify.toml

    [build]
      command = "npm run build"
      publish = "public"
    
    [[redirects]]
      from = "https://some-domain.netlify.com/*"
      to = "https://www.mydomain.tk/:splat"
      status = 301
      force = true
    

    There is a playground to build them from the _redirects format to netlify.toml format