Netlify Rewrite Question

Hi there,

I am trying to get what I think is a simple rewrite working, but I may be completely misusing the feature…

Firstly I have 2 netlify sites. One is our main site built using gatsby. A second site is just a _redirects file that I would like to rewrite to a single page on the main site. Previously this was a redirect but I would prefer a rewrite if it is possible.

The rewrite file looks like this for the smaller site.

/*   https://www.thec3.uk/academy:splat 200

The current behaviour is that I visit https://thec3.academy and I get a 301 to https://www.thec3.uk/academy, where I would prefer if the page rendered as a 200 with the address https://thec3.academy

Thanks in advance!

Andy

Further to the above here is the updated link to the redirects file as I discovered there was an extra redirect due to a lack of trailing slash. However I still have a redirect where I would like a rewrite if possible!

Hey @nanorepublica,

Are both of these sites on the same Netlify team? If not, we can’t allow the rule for security reasons.

So long as the sites are on the same team, could you try:

/* https://www.thec3.uk/academy/:splat 200

I think that this rule may be failing because we’re missing the / after /academy.

Hi @Pieparker

Yes they are both on the same team. I have updated the rule as you suggested but still no luck

This is the output of doing a HEAD request to https://thec3.academy from curl following redirects

$ curl -IL  https://thec3.academy
HTTP/2 301
cache-control: public, max-age=0, must-revalidate
content-length: 0
content-type: text/plain
date: Fri, 01 May 2020 17:23:31 GMT
link: </webpack-runtime-c786aec87fc50a85ecfb.js>; rel=preload; as=script, </commons-a403bf3be1c61fb338d6.js>; rel=preload; as=script, </app-13320ba305b3d1ec0925.js>; rel=preload; as=script, </styles-80dcf2c0ba6853a67d0a.js>; rel=preload; as=script, </commons-a403bf3be1c61fb338d6.js>; rel=preload; as=script, </component---src-pages-academy-jsx-1a8bfcdaf04b528661ac.js>; rel=preload; as=script
location: https://thec3.uk/academy/
referrer-policy: same-origin
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
age: 0
server: Netlify
x-nf-request-id: 03ac58e6-e280-4b3c-a60f-16d01df7189a-5651462

HTTP/2 200
cache-control: public, max-age=0, must-revalidate
content-length: 0
content-type: text/html; charset=UTF-8
date: Fri, 01 May 2020 17:23:32 GMT
etag: "bb55482b6e6d1adf01eac92702b53895-ssl"
link: </webpack-runtime-c786aec87fc50a85ecfb.js>; rel=preload; as=script, </commons-a403bf3be1c61fb338d6.js>; rel=preload; as=script, </app-13320ba305b3d1ec0925.js>; rel=preload; as=script, </styles-80dcf2c0ba6853a67d0a.js>; rel=preload; as=script, </commons-a403bf3be1c61fb338d6.js>; rel=preload; as=script, </component---src-pages-academy-jsx-1a8bfcdaf04b528661ac.js>; rel=preload; as=script
referrer-policy: same-origin
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
age: 0
server: Netlify
x-nf-request-id: 03ac58e6-e280-4b3c-a60f-16d01df7189a-5651977

I am making the assumption that a working rewrite would just return a 200 instead of a 301 then a 200. Is this correct?

Thanks

Andy

Additionally, I just invoke curl normally with no options I get the following:

$ curl  https://thec3.academy
Redirecting to https://thec3.uk/academy/

Am I correct in assuming this is the 301 response back from Netlify?

Hey @nanorepublica,

That’s right, it appears to be 301’ing. I’ve tried testing this on a test repo but I’m not actually able to replicate. I’ll share with my peers and feed back when I know more :+1:

What I will say is that your secondary site (https://thec3.academy) has zero content and it’s being used purely for the redirect. Additionally, your DNS is not at Netlify. You may find that your domain registrar/DNS provider offers stealth forwarding or URL cloaking, allowing you to rewrite without having this secondary, almost empty repo :smile:

1 Like