Redirects do not behave as expected

Hi

Let’s start with a bit of context, I have created a statically generated blog that we want to display as a subfolder of our website hosted elsewhere. (https://360mooc.com/blog/)

I am not very experimented on this subject but I understood that I needed to deploy the blog on the main domain and proxy requests that are meant for the website from Netlify.

Here are the redirects rules that I added to netlify.toml

[[redirects]]
    from = "/blog*"
    to = "/blog:splat"
    status = 200
    force = false

[[redirects]]
    from = "/*"
    to = "http://website.360mooc.com/:splat"
    status = 200
    force = true
    headers = {X-From = "Netlify", X-Forwarded-Host = "360mooc.com"}

However, when I tried accessing the base route (https://360mooc.com) after that, netlify responded with a 301 redirect instead of a 200 proxy.

age: 32
content-length: 178
content-type: text/html
date: Wed, 10 Jun 2020 13:36:33 GMT
location: https://website.360mooc.com/
server: Netlify
status: 301
x-content-type-options: nosniff
x-nf-request-id: 35132e8a-bef8-4da2-896b-cbae76fec0ee-3441662

I have tried redeploying and clearing my local cache and the cache of Netlify
image

EDIT: The weird thing is that the redirects work as intended on my netlify subdomain https://360mooc.netlify.app/

Does anyone know what could be the issue here?

Hi, @jeremy.b, the 301 redirect is coming from the site being proxied to:

$ curl -svo /dev/null http://website.360mooc.com/  2>&1 | tail -n 12
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Thu, 11 Jun 2020 07:56:40 GMT
< Content-Type: text/html
< Content-Length: 178
< Connection: keep-alive
< Location: https://website.360mooc.com/
< X-Content-Type-Options: nosniff
<
{ [178 bytes data]
* Connection #0 to host website.360mooc.com left intact
* Closing connection 0

This happens because you are proxying to the HTTP (not the HTTPS) url:

    to = "http://website.360mooc.com/:splat"

If you change that to the HTTPS version, it should return a 200 response:

    to = "https://website.360mooc.com/:splat"

If there are other questions, we’ll be happy to answer.

Hi @luke,

This solves my problem, thanks for your answer.