Home
Support Forums

Cloudflare flattened CNAME => Netlify site => [[redirects]] returns 404 instead of 301

Site name: https://saaspm.netlify.app

Problem: this site’s purpose in life is to redirect to another site. This redirection works great when I navigate to https://saaspm.netlify.app or https://saaspm.netlify.app/ directly. But when I try to use a Cloudflare flattened CNAME (using DNS-only “gray cloud” not proxied “orange cloud”) to https://saaspm.com, then I get a 404 error from Netlify instead of a 301 redirect.

Example of going through Cloudflare DNS: (this fails)

justingrant@jgmac bin % curl -v saaspm.com 
*   Trying 184.72.37.151:80...
* Connected to saaspm.com (184.72.37.151) port 80 (#0)
> GET / HTTP/1.1
> Host: saaspm.com
> User-Agent: curl/7.77.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< cache-control: private, max-age=0
< content-length: 50
< content-type: text/plain; charset=utf-8
< date: Wed, 17 Nov 2021 22:50:20 GMT
< server: Netlify
< age: 0
< x-nf-request-id: 01FMR1G150X1GN7J5Q8067AXXE
< 
* Connection #0 to host saaspm.com left intact
Not Found - Request ID: 01FMR1G150X1GN7J5Q8067AXXE

Example of direct to Netlify: (this works)

justingrant@jgmac bin % curl -v saaspm.netlify.app
*   Trying 54.241.68.193:80...
* Connected to saaspm.netlify.app (54.241.68.193) port 80 (#0)
> GET / HTTP/1.1
> Host: saaspm.netlify.app
> User-Agent: curl/7.77.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< cache-control: public, max-age=0, must-revalidate
< content-length: 38
< content-type: text/plain; charset=utf-8
< date: Wed, 17 Nov 2021 23:00:43 GMT
< server: Netlify
< location: https://www.saaspm.com/
< x-nf-request-id: 01FMR23NEXSZR8N1M0ABGZJD2W
< age: 20
< 
* Connection #0 to host saaspm.netlify.app left intact
Redirecting to https://www.saaspm.com/

You need to add the domain to your website :slightly_smiling_face::

https://app.netlify.com/sites/saaspm/settings/domain#custom-domains

Ahh, yep that was the problem. Even though Netlify isn’t actually handling DNS for saaspm.com, to fix the error above I needed to add it as a custom domain to this site.

There was also a separate problem: I needed to update the [[redirects]] section to include saaspm.com URLs as from redirects. Which makes sense because it’s using the host header to match against from, and the CNAME doesn’t change the host header.

Thanks for your help!

BTW, here’s the part of the docs that discusses the issue above: Redirect options | Netlify Docs