Trying to proxy, but get a redirect

Hi there!

I’m trying to set up a proxy from our new Netlify website to our old website for a few pages that are not yet ported. However, despite using a 200 in the _redirects file, the URL in the browser changes - Netlify redirects instead of proxying.

Rewrite rule in question is here:

/pipeline_schema_builder/* https://oldsite.nf-co.re/pipeline_schema_builder/:splat 200!

What I want is to go to https://nf-co.re/pipeline_schema_builder and the browser URL remain as such (with a 200 response). Instead, it redirects to https://oldsite.nf-co.re/pipeline_schema_builder , replacing the URL.

What am I missing here? As far as I can tell it should be the same setup as described in the docs?

Thanks,

Phil

Your destination is serving a 301:

curl -I "https://nf-co.re/pipeline_schema_builder"
HTTP/2 301
location: https://oldsite.nf-co.re/pipeline_schema_builder

This is working as intended.

Not really - the redirection is working, but I want a rewrite / proxy.

From the docs:

When you assign an HTTP status code of 200 to a redirect rule, it becomes a rewrite . This means that the URL in the visitor’s address bar remains the same, while Netlify’s servers fetch the new location behind the scenes.

This can be useful for […] transitioning for legacy content.

Now all requests to /api/... will be proxied through to https://api.example.com straight from our CDN servers without an additional connection from the browser.

So what I would like to see is this (hand-typed example):

curl -I "https://nf-co.re/pipeline_schema_builder"
HTTP/2 200
...

In other words, I don’t want to see oldsite.nf-co.re anywhere in the response.

However, currently it is redirecting with a 301 (the default behaviour for netlify redirection if no code is specified).

Your destination server is sending a 301. Netlify is passing it along. Stop sending a 301 from your destination server if you don’t want a 301.

Argh you are of course completely correct :man_facepalming: :see_no_evil:

I was sure that this wasn’t the case because running curl on the oldsite gave a 200:

❯ curl -I https://oldsite.nf-co.re/pipeline_schema_builder
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Sun, 16 Jul 2023 18:05:22 GMT
server: Apache

However, that wasn’t the URL that Netlify was trying to fetch - there was a trailing slash, and I had a long-forgotten .htaccess redirection rule set up to remove trailing slashes :see_no_evil:

❯ curl -I https://oldsite.nf-co.re/pipeline_schema_builder/
HTTP/2 301
location: https://oldsite.nf-co.re/pipeline_schema_builder
content-type: text/html; charset=iso-8859-1
date: Sun, 16 Jul 2023 18:03:02 GMT
server: Apache

I removed the R=301 from that and now, sure enough, I get a 200 response from Netlify:

❯ curl -I "https://nf-co.re/pipeline_schema_builder"
HTTP/2 200
age: 1
content-type: text/html; charset=UTF-8
date: Sun, 16 Jul 2023 18:05:31 GMT
server: Netlify
strict-transport-security: max-age=31536000
x-nf-request-id: 01H5FY22E4FEGSK8EXNYVWKWCC

Notably, the browser does still switch out the address bar to https://oldsite.nf-co.re/pipeline_schema_builder when I visit https://nf-co.re/pipeline_schema_builder - but in my current use case all I need is the 200 code so this isn’t a problem.

Many thanks for your help @hrishikesh and apologies that it took me a while to get there… :bowing_man: