使用CURLOPT_FOLLOWLOCATION设置为true将日志卷曲重定向

I have an script that grabs content from third party sites and if the url is not found the site redirects with a 302 header location to a custom not found webpage instead of sending a 404 not found. The script also caches the content returned by curl_exec but i don't want to cache the error pages, so is there a way to log those redirects if i have turned on CURLOPT_FOLLOWLOCATION? How can i solve this situation? I know i could just find the error message using a dom parser and if found just discard it, but i want to know if there is other ways to accomplish this.

I ended up disabling followlocation so i just have to catch the 302 code and if it's present i don't cache the page. Thought there would be a way of catching all codes before curl redirects.

Have a look at Easy way to test a URL for 404 in PHP?

Then using that, just do not cache the page if there is a 404