Gateway timeout (error 504) when redirect in php is sent

Check your SSL/TLS setting is set to “Full (strict)” in your dashboard here…
https://dash.cloudflare.com/?to=/:account/:zone/ssl-tls

Otherwise, what is the website?