2 minutes
WordPress Curl on page returns 200 but browser returns 404
👴 Careful You’re reading an old article ! Some links might be broken and content may be outdated
I had a weird issue on a PHP script. I was returning an error 404 on a WordPress page the following way :
When I was accessing the error page on the browser, It worked well, I had a 404 error page displayed + the correct status code when I inspected the page (Network tab).
However, when I was « curl-ing » the same error page, it didn’t work. It didn’t work in the shell, or in the PHP script.
The Shell command I did :
The buggy PHP Script
Solution
I had to remove the « CURLOPT_NOBODY » to get the correct status code.
Read other posts