Template_redirect works, but headers aren't sent when checking via cURL
I'm creating a 307 redirect to maintenance page for when my site goes through maintenance.
My PHP class is included in functions.php, and gets instantiated immediately.
In my __construct, I call:
add_action('template_redirect', [ $this, 'redirectToMaintenance' ] );
Then my redirectToMaintenance() method looks like this:
public function redirectToMaintenance() {
$pageToLoad = get_the_permalink(123); // for test page ID
header( HTTP/1.1 307 Temporary Redirect );
header(Location: . $pageToLoad );
die();
}
This works perfectly, but if I try:
curl -iL https://example.com
No redirects are detected.
Same thing when I check via wheregoes.com.
I've tried redirecting with hooks other than template_redirect but they don't seem to work well.
Any idea on what I could be doing wrong?
Thanks!
Topic template-redirect redirect hooks Wordpress
Category Web