How to redirect only GET requests with Netlify's .toml

I currently have a website set up where we redirect the requests from our root (’/’) into a language specific page (’/en’ or ‘/pt’) depending on the user’s language. However that rule disables our form submissions, since POST requests sent to the root get 301 redirected as well. Is there any way to set up the redirect rules so that only GET requests to the root get redirected, or maybe a different form submission config?

Thank you,
Bruno Cangussu

Hi @Cangussu,

We don’t have that functionality at present (method-specific redirects).

Not sure how you have your redirects set up, but I’d suggest deploying an actual file at the URL you want to submit to (e.g. <form action=/page.html> and have /page.html deployed), and then if you use non-forced redirects:

/* /pt/* langauge=pt
/* /en/* language=en

things should work. If not, you could have a /pt/page.html and a /en/page.html and make their corresponding forms submit to the different endpoints, perhaps?

Hi @fool,

The redirect we currently have is simply a

[[redirects]]
  from = "/"
  to = "/pt/"
  status = 301
  force = true

If not, you could have a /pt/page.html and a /en/page.html and make their corresponding forms submit to the different endpoints, perhaps?

How would that work? We’re just using the basic Netlify’s forms settings, which needs the POST to hit the root, from what I understand. The contact forms for the different languages don’t need a separate endpoint since it’s the same employee that will be handling the user contact

The issue is mainly that we don’t want an empty root page because it’s bad for indexing, but redirecting it breaks the form for now, so we’re kinda lost :confused:

The POST needs to go wherever you define the action for the form in its html definition (as we parse it at build time, from whatever html file you define it in). A more expanded version of what I was suggesting:

  1. make two versions of the form - one english and one portuguese. They must have different <form name=????> identifiers (or if javascript, a field called form-name with different values)
  2. make them submit to different places - e.g <form action=/en/success.html ...> and <form action=/pt/sucesso.html>
  3. profit :slight_smile: