Detecting headers in redirects


I have a site setup as so: is my main site, not on netlify is my site on netlify

Any requests to are proxied to using a cloudflare worker ( is NOT proxied by cloudflare at the moment)

This is working as it should.

However, I’d like to block direct access to - or at least redirect any requests* to

Is there a way to do this using the _redirects or netlify.toml file?

My fallback option is to run a second worker on cloudflare that can detect if my proxy is doing the request (by sending and detecting an type header in the two worker scripts respectively)



Hello, @guybowden, and welcome to our Netlify community site. :slight_smile:

In _redirects format, this can be done using the following:* 301!

This forces a 301 redirect for any attempt to load the site via . To get this to work, one must replace the target domain and * subdomain with the appropriate values for your site.

​Please let us know if there are other questions or if this doesn’t work as promised.

Thanks for that - however I’m not sure it would address the issue where I do want to work as normal (i.e. no redirects) if the request is coming via my reverse proxy. But not for a direct browser request.

@guybowden, I missed that you wanted to allow it via proxy to Netlify.

First, I must mention that we do not support being proxied to. That being said, people do use proxies in front of their Netlify sites but we do not provide technical support for these configurations.

You can use Netlify as a proxy to another service and we provide support for that. Again, though, we do not support the reverse configuration.

Regarding being able to conditionally redirect based on the presence (or absence) of an HTTP request header, we have an open feature request for this. I’ve cross linked the feature request to this community topic for tracking and we’ll reply here, if/when the issue is resolved.

Other people finding this post, please :heart: the original post above if you want to see this feature request as well.

Thanks for the update. I will look at doing it a different way for now.

1 Like